Possible Duplicate:
Sorted ArrayList not displaying?
Code:
String title1 = "Original Order\n\n";
String title2 = "Sorted Order\n\n";
String collection = "";
for (int i = 0; i < cdcollection.size(); i++) {
collection = collection + cdcollection.get(i);
}
mainTextArea.setText(title1 + collection);
Collections.sort(cdcollection);
String temp = "";
for (int j = 0; j < cdcollection.size(); j++) {
temp += cdcollection.get(j);
}
mainTextArea.setText(title2 + temp);
I took your code without the swing code and the list is sorted properly. See the code below
The for loop you used here
Dont add the
title2in the loop and calling setText in loop will over write the old text. Append all the string from the list in a temp string and in the last set in the in themainTextArea. Something likeBut this is definitely a duplicate as mentioned by Alexander. you could have edited the same question.