Questions tagged «conditional-execution»

21
Java中for循环增强的最后一次迭代
有没有一种方法可以确定循环是否在最后一次迭代。我的代码如下所示: int[] array = {1, 2, 3...}; StringBuilder builder = new StringBuilder(); for(int i : array) { builder.append("" + i); if(!lastiteration) builder.append(","); } 现在,我不想在最后一次迭代中添加逗号。现在有一种方法可以确定是最后一次迭代,还是我陷入了for循环还是使用外部计数器来跟踪。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.