Welcome, Nuluvius, to Java Forums
There is a very easy solution for your problem. You can use the String.indexOf() method to determine if a String is a substring of another. I did this:
public static boolean contains(String string1, String string2){
return -1 != string1.indexOf(string2);
}
In my testing class, I had:
package pack;
import java.util.*;
public class Test{
public Test(){
System.out.println("Test running");
System.out.println("Enter string1:");
String string1 = Tools.readln();
System.out.println("Enter string2:");
String string2 = Tools.readln();
System.out.println("Result = " + contains(string1, string2));
}
public static boolean contains(String string1, String string2){
return -1 != string1.indexOf(string2);
}
}
output:
Test running
Enter string1:
true love
Enter string2:
love
Result = true
I hope this helps you.
