java.util.LinkedHashMapLinkedHashSet 中的 $LinkedKeyIterator 无限循环

java.util.LinkedHashMap$LinkedKeyIterator infinite loop in LinkedHashSet

System.out.print("Enter the size of linked hash set: ");
    Scanner s = new Scanner(System.in);  // Create a Scanner object
    int size = s.nextInt();
        HashSet<String> lhashset = new HashSet<>(size);
    for(int i=0; i<size; i++)
    {
        System.out.print("Enter the name: ");
        String name = s.next();
        lhashset.add(name);
    }
        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? ");
            String ch = s.next();
        String choice = "yes";
            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.");
        }

第一个 if 语句工作正常,但是当我尝试转到 else 语句 (print"does not contain") 时,我得到了标题中的无限循环。嵌套的 if 语句也是如此。

ch.equals(选择)将不起作用。使用正确的语法更新代码。

public class Soln {
public static void main(String[] args) {
    Scanner s = new Scanner(System.in);  // Create a Scanner object
    HashSet<String> lhashset = new HashSet<>();
    lhashset.add("TEST");
    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 == 1)
        {
            lhashset.remove(find);
            System.out.println("\nElement removed.");
        }
        else
        {
            System.out.println("\nGoodbye");
        }
    }
    else
    {
        System.out.println("Does not contain name.");
    }
}
}