Find the first index of the substring. Condition: Do not use java library function or regular expressions. And measure the performance of your implementation with the standard java library function. Examples: String 1: “abcdefg” String 2: “bcd” Should return 1 String 1: “abcdefg” String 2: “x” Should return -1
Anónimo
public class ComputeSubString { String s1 = "abqqqqqqqbcdef"; String s2 = "xbcd"; boolean found = true; static int pos = -1; public static void main(String s[]) { new ComputeSubString().start(); System.out.println(pos); } private void start() { for (int i = 0; i s1.length() || s1.charAt(index + i) != s2.charAt(i)) { return false; } } return true; } }