Answers for "how to get substring from string in java"

10

how to do substring java

class Main {
  public static void main (String[] args) {
    
    String str = "Hello World!";
    
    String firstWord = str.substring(0, 5);
    //two parameters are start and end index: (inclusive, non-inclusive)
    
    String secondWord = str.substring(6, 11);
    
    //firstWord has string "Hello"
    //secondWord has string "World"
  }
}
Posted by: Guest on May-27-2020
1

java get substring

// substring(int begin, int end)
String n = "hello there general kenobi";
System.out.println(n.substring(6, 11));
// -> "there"
Posted by: Guest on March-14-2021

Code answers related to "how to get substring from string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language