This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Please help me to explain this result

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Could you explain help me result of this code please? I don't know why it return that result. I thought it returns A,B,C,D,E or A,C,D,B,E but I was wrong .



package generic;

import java.util.HashSet;
import java.util.Set;

/**
* Created by HungNV6.
* User: Viet
* Date: 20/03/2011
* Time: 21:14
*/
public class Set1 {
public static void main(String... args){
Set<String> s = new HashSet<String>();
s.add("A");
s.add("C");
s.add("D");
s.add("B");
s.add("E");

for (Object o: s){
System.out.println(o);
}
}
}


==> Compiler returns: D, E, A, B, C

Thanks,
Viet Hung
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. The explanation is exactly the same as for your last question. Did you see that?
reply
    Bookmark Topic Watch Topic
  • New Topic