How to exit loop with ENTER
问题 How do I exit this loop when user presses ENTER. This is part of the codes I have done. I am having problems in how to code when user presses ENTER. static String[] itemList = new String[10]; do { System.out.print("Enter item (press ENTER to exit) " + (count + 1) + ": "); String item = input.next(); itemList[count] = item; if (item == "") count = itemList.length; 回答1: You are comparing String s using == not .equals() . This compares the pointer to the String , not the contents of the String .