Share on Google+Share on Google+

SCJP Module-9 Question-23

Ads
The sample code given below will check your understanding about the sorting string of an ArrayList object.

Given below the sample code :

import java.util.*;
public class SortStrings{
public static void main(String[] args) {
ArrayList<String> str = new ArrayList<String>();
str.add("bBbB");
str.add("BbB");
str.add("bBb");
str.add("BBbb");
Collections.sort(str);
for (String a : str) { System.out.print(a + " "); }
}
}

What will be the output of the above code ?

 1. bBbB bBb BBbb BbB

2. BBbb Bbb bBb bBbB

3. BbB BBbb bBbB bBb

4. bBb BbB bBbB BBbb

Answer

(2)

Advertisements

Posted on: July 19, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.