aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes HashSet and sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "HashSet and sorting" Watch "HashSet and sorting" New topic
Author

HashSet and sorting

mohammad shaid
Ranch Hand

Joined: May 05, 2010
Posts: 86
From Devaka's exam lab Simulator... i changed the Collection type from ArrayList to HashSet.. this code doesnt compile.. well.. i am sorting String elements here.. and it should be sorted.. but i get Compiler Error at invoke of Collections.sort() method



Thanks & Regards,
shaad
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

1. What is the error message ? Isn't it explicit enough ?
2. Did you check the API of Collections#sort ? Does it allow to sort a Set ?


[My Blog]
All roads lead to JavaRanch
mohammad shaid
Ranch Hand

Joined: May 05, 2010
Posts: 86
its showing ke sort method is not found in java.util.Collections class...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Christophe Verré wrote:2. Did you check the API of Collections#sort ? Does it allow to sort a Set ?

Did you do this??
mohammad shaid wrote:its showing ke sort method is not found in java.util.Collections class...

The word in the bold I suppose is in Hindi or something which means "that"...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
mohammad shaid
Ranch Hand

Joined: May 05, 2010
Posts: 86
yea.. sorry.. thats a hindi word
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

we cannot sort the Hashset using Collection.sort() as sort method does not accept the HashSet as parameter
I think you should look into the API


SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashSet and sorting