Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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?
 
crispy bacon. crispy tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic