• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Please help me to explain this result

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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