This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

index question-arraylist  RSS feed

 
pravin kumar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen when you attempt to compile and run the following code?

import java.util.*;
public class SortList{
public static void main(String argv[]){
new SortList();
}
SortList(){
ArrayList<String> al = new ArrayList<String>();
al.add("z");
al.add("b");
al.add("c");
Collections.sort(al);
for(String element : al){
System.out.print(element);
}
}
}


Answer is dcz ..please explain
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you mean bcz. There is a method call Arrays.sort(al) that will sort the ArrayList.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops I mean Collections.sort
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!