jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes index question-arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "index question-arraylist" Watch "index question-arraylist" New topic
Author

index question-arraylist

pravin kumar
Ranch Hand

Joined: Nov 03, 2005
Posts: 30
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

Joined: Feb 07, 2005
Posts: 2341
I assume you mean bcz. There is a method call Arrays.sort(al) that will sort the ArrayList.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
Oops I mean Collections.sort
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: index question-arraylist
 
Similar Threads
Generics problem?
readonly ArrayList
Can a.equals(b) be true for a b which does not pass the instanceof test for the class of a?
Equals() method doubt
How do you avoid an ArrayList object from being modified, i.e. avoid adding and deleting its content