• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ordered and Sorted

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"When a collection is ordered, it means you can iterate through the collection in a specific (not - random) order." - What does this staement mean ?
When we say HashSet() is unsorted and unordered, what does that mean ?
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we say any collection is ordered, it means that when you iterate over the collection, the output is predictable. For example if I have the following code
If I iterate over this ArrayList, I know that "A" will be the first element to be iterated, then "B" then "C" and then "D". So I can predict the iteration sequence. This means that the collection is ordered (insertion order in case of ArrayList). But if you iterate over a HashMap, you can't predict the iteration order because HashMap doesn't guarantee any iteration order. So you can't predict in which order elements will be iterated in a HashMap and thus its unordered...
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple When you will sort the collection then you can iterate in sorted order.

HashSet is not sorted and ordered collection.

There are many types of set some are sorted and ordered., some are unordered and unsorted .

It's all depand upon your requirement when to you what....

reply
    Bookmark Topic Watch Topic
  • New Topic