aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Whats the output??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Whats the output??? " Watch "Whats the output??? " New topic
Author

Whats the output???

himanshu kesarwani
Ranch Hand

Joined: Aug 27, 2008
Posts: 84
class flub
{
public static void main(string arg[])
{
List<String> x=new ArrayList<String>();
x.add("x"); x.add("xx"); x.add("Xx");

//insert code here

for(String s: x) system.out.println(s);
}
}


output:
xx
Xx
x


ANSWER IS:
Comparator c=Collection.reverseOrder();
Collection.sort(x,c);




GUYS i am getting just nothing that :
1. why comparator, and where is its overridden method and class .
2.what is reverseOrder(); its first time i am lookin at this .

please guys,kindly clarify how this output is coming?? and how all this Comparator is working here !!

SCJP 5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

2.what is reverseOrder(); its first time i am lookin at this

That's a typo in the answer. Look for Collections#reverseOrder in the API.


[My Blog]
All roads lead to JavaRanch
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
The


returns a comparator which will use to reverse the data in reverseorder. So in the sort function the comparator object is passed to decide the manner
in which data need to be sorted.


My Techie Blog - Java Questions
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Please use code tags while posting code on the forum


Regards, Sud.
SCJP 5 ScjpFAQ JLS
himanshu kesarwani
Ranch Hand

Joined: Aug 27, 2008
Posts: 84
kindly,explain clearly!!
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
The


takes comparator as parameter. So each element is compared with the other using the overriden method for the interface and the collection is sorted in
that manner. Please check the implementation of reverseOrder method in jdk source.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whats the output???