How to check if a substring start with specified substring in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String s = "java c++ c";

            if (s.startsWith("c++", 5)) 
                System.out.println("yes");
            else
                System.out.println("no");

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
yes
  
 */

 



answered Nov 22, 2016 by avibootz

Related questions

...