Dear javaprogrammingforums administrator and members,
Hello everyone, I hope everyone is fine upon reading this thread of mine. I'm currently reading "Java How to Program Third Edition by Deitel and Deitel" and exploring about Collections Framework. I tried to program one of their source codes about the Set interface implemented by HashSet. I edited it a little though. By the way, here's the code:
[FONT="Courier New"] import java.util.*; public class Sample{ public static void main(String [] args){ String colors[]={"green","red","blue","red","blue","white", "orange","black"}; List list = new ArrayList(Arrays.asList(colors)); System.out.println(list); HashSet ref = new HashSet(list); Iterator i = ref.iterator(); System.out.println("\n\nElements with no duplicates:"); while(i.hasNext()){ System.out.print( i.next()+ " "); //Line 11 } }//main }//class [/FONT]
The program works fine, but I just wonder why the ourput in Line 11 is in this order?
orange red blue green white black
I am really expecting this output:
green red blue white orange black
I hope someone would give more information about why this came to be. I hope this is not too much to ask.
Thank you and God bless everyone.
Respectfully Yours,
MarkSquall