What will be the following code execution result?

class HashTest {
    private static Set<String> set = new LinkedHashSet<String>();
    public static void main(String[] args) {
        set.add("one");
        set.add("two");
        set.add("three");
        set.add("two");
        for (String string : set) {
            System.out.print(string + " ");
        }
    } 
}
Explanation
LinkedHashSet remembers the order of the elements insertion. As the entities are added to the table they are linked to a bidirectional linked list.
Iterator will iterate through its values ​​in the order in which they were inserted.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback