• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashSet and sorting

 
mohammad shaid
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
mohammad shaid
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its showing ke sort method is not found in java.util.Collections class...
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"...
 
mohammad shaid
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea.. sorry.. thats a hindi word
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic