ArrayList cdcollection = new ArrayList();
private void initButtonActionPerformed(java.awt.event.ActionEvent evt) {
Collections.addAll(cdcollection, \
You have defined collection
as a string like String collection = "";
. There is no method called get(j)
in String class. Try to use your arraylist object cdcollection
. Also take of the creation of arraylist. You have done like ArrayList <String> cdcollection = new ArrayList();
, try to use generics both the sides like ArrayList <String> cdcollection = new ArrayList<String>();
, otherwise you might get unnecessary warnings.
EDIT:
public static void main(String[] args){
ArrayList<String> cdcollection = new ArrayList();
Collections.addAll(cdcollection, "renier\n", "mert\n", "rain\n",
"mylen", "dreb\n");
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);
}
System.out.println(title1 + collection);
Collections.sort(cdcollection);
System.out.println(cdcollection);
}