• Post Reply Bookmark Topic Watch Topic
  • New Topic

sorted or ordered  RSS feed

 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is different betwenn sorted and ordered when considering collection?
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this...
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slightly confusing link, but it does give the general direction.

People often use "sorted" and "ordered" rather loosely, but that link does tell you that it is possible to go through an ordered collection and retrieve the first-entered value first, then the second, etc. That link is confused about LinkedList and ArrayList, saying that you add to the end of a LinkedList and to the index in an ArrayList. It is usual to add to the end of an ArrayList, and it is possible to add to an index in a LinkedList. By inserting elements in the middle of a List, you are altering the order.

It is correct about "sorted"; you can get elements out in a sequence determined by their "values". You can alter the sequence of "values" by changing Comparators or a compareTo method or similarly.

You can also sometimes get Collections ordered backwards (eg a Stack) or iterate through collections backwards.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!