how can I check in an arraylist for the same String while ignoring cases? Sorry in advance, I'm new at Stackoverflow
ArrayList listednames = new ArrayList<>();
while (true) {
String entry = JOptionPane.showInputDialog("name:");
if (entry == null) {
break;
}
entry = entry.trim();
if (entry.equalsIgnoreCase("stop")) {
break;
}
if (entry.isEmpty()) {
continue;
}
if (listednames.contains(entry)) { // .equalsIgnoreCase wont work with lists
continue;
}
listednames.add(entry);
Collections.sort(listednames);
String namen = listednames.toString();
namen = namen.substring(1, namen.length()-1);
System.out.println(namen);
}
}
}
Aucun commentaire:
Enregistrer un commentaire