How to find the index of substring in StringBuilder with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        StringBuilder sb = new StringBuilder("java programming");
 
        int index = sb.indexOf("pro");
        System.out.println(index);

        index = sb.indexOf("abc");
        System.out.println(index);
    }
}
 
 
 
/*
run:
 
5
-1
 
*/

 



answered Oct 29, 2020 by avibootz

Related questions

1 answer 170 views
1 answer 155 views
1 answer 166 views
1 answer 147 views
...