How to get a substring from the first character of a String in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String s = "java c c++";

            String part = s.substring(0, 4);
            System.out.println(part);

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

/*
             
run:

java
    
 */

 



answered Nov 26, 2016 by avibootz
...