[JAVA] Slice String in Java

  • String.substring(int beginIndex) //slice from beginIndex to the end of string
  • String.substring(int beginIndex, int endIndex)
public class StringExample
{
    public static void main(String[] args)
    {
        String string1= “hello world”;
        System.out.println(string1.substring(0, 2)); //he
        System.out.println(“hello world”.substring(6)); //world
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *