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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes