dimanche 5 avril 2020

java.util.LinkedHashMap$LinkedKeyIterator infinite loop in LinkedHashSet

System.out.println("\nEnter the name you want to find: ");
    String find = s.next();
    if(lhashset.contains(find))
    {       
        System.out.println("\nYes the Linked Hash Set contains " +find);
        System.out.print("Do you want to remove the name? ");
        int ch = s.nextInt();
        if(ch.equals(choice))
        {
            lhashset.remove(find);
            System.out.println("\nElement removed.");
        }
        else
        {
            System.out.println("\nGoodbye");
        }
    }
    else
    {
        System.out.println("Does not contain name.");
    }

The first if statement works fine, but when I try to go to else statement("does not contain"), I get an infinite loop as per the heading. The same happens for the nested if statement.

Aucun commentaire:

Enregistrer un commentaire