+ 2
iterate over a Hashset
Hello....!! could some one check the link below and explain this to me I do not understand why the input is / **popularLanguages.add("java") ; popularLanguages.add("c++") ; popularLanguages.add("c# ") ; popularLanguages.add("c") ; popularLanguages.add("kotlin") **/ and the output is c# python java java c++ instead of c++ as a simple array c c# Kotlin c python kotlim https://code.sololearn.com/csBVE3T2yGhK/?ref=app and how to get the same order in output as in imput when using a Set table
3 Answers
+ 2
You can use LinkedHashSet to maintain elements in insertion order.
You can use TreeSet to maintain the elements in sorted order.
+ 2
i don't master my question well but the problem was about how to maintain insertion order when using a set and as you say on top i have use a LinkedHashSet and it work thans to all you
0
String popularLanguage = popularLanguageIterator.next() ;
// You can remove the above line and use the below to get the same result.
System.out.println(popularLanguageIterator.next());
Also if you want to display it as an array or a list then you can do-
System.out.println(popularLanguages.toString());
Edit: I don't think if I understood the question well but these may be a couple tricks you can use to make things easier.