'Is there a way to search an array for a value in the array in its string form?
I have an array in which I am trying to ask the user a question, have them give their answer (and in their answer will be a string value in the array), and then use their answer to formulate a response to them. I tried using .equals and changing the array into a list. Right now I am using a boolean to find if the string from the array is present in the user's answer or not, but I want the code to be very flexible (which means I want it not to matter if the user says "Hi" or "hi". Here's the code below:
String[] albums = {"positions", "thank u, next", "sweetener", "k bye for now",
"dangerous woman", "my everything", "yours truly"};
String firstQuestion = ari.nextLine();
boolean isFound0 = firstQuestion.contains(albums[0]);
if (isFound0) {
System.out.println("tysm! i love " + (albums[0]) + " as well!");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
