• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
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?
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic