Hi there,
I am implementing the indexOf method of the string class to check whether a string value exists in another as in the code below:
String str = "9,10,11,12";
String isIn = JOptionPane.showInputDialog("Please enter a number");
int x = str.indexOf(isIn);
if(x != -1)
{
System.out.println("Not in");
}
else
{
System.out.println("in");
}
The problem here is that if the user enters "1", 1 is in the string as the number 11. How would I be able to write the code such that it can differentiate between 1 and 11? I have thought about it and I just cannot figure out how it can be done. I am new to java and I would appreciate some assistance in this regard.
Thanks
