Here\'s a method for sorting an integer array. How can I remove the last separator form the output?
public void Sort(int[] sort) {
for (int a:sort) {
You may use a StringBuilder as follows:
StringBuilder sb =new StringBuilder();
int[] sort = {1,2,3,4,5,7,89,4,9,6,11,23,178,29};
for(int i : sort) sb.append(i+", ");
if(sb.length()>2) sb.delete(sb.length()-2, sb.length());
System.out.println(sb.toString());
EDIT: This is not the sorting algorythm. This is just an example of how you can present it without the last comma.