I want to take a String of words that are separated by spaces, and separate each word, and then compare it to another string.
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("potato");
String a = "potato salad";
String[] x = a.split(" ");
System.out.println(""+x[0]);
System.out.println(""+list.get(0));
if(list.get(0) == x[0])
{
System.out.println("they same");
}
else
{
System.out.println("they not same");
}
}
}
When i print them, they both print the same string does that mean that the split method returns something other than an array of strings? How can I go around the problem to get the desired result.