I am trying to write a method that takes a String, converts it into an Array of Strings, and then searches for a specific String within that Array. Here is my code:
public static void ThereOrNaw ( String s, String s2 ){
String[] words = s.split("\\s");
for (int i = 0; i < words.length; i++) {
words[i] = words[i].replaceAll("[^\\w]", "");
}
for ( int i = 0; i < words.length; i++) {
if( s2 == words[i] ) {
System.out.println("Found");
}
else if( s2 != words[i] && (i + 1) == words.length) {
System.out.println("Not Found");
}
}
}
However, when I run this method it always returns "Not Found" even if the element is in the Array. Unless, the Array of Strings has ONLY the element I am looking for. Any ideas why this isn't working?