How to use BigInteger in Java - 2
May 31, 2023
1 min
The substring method in the String class functions to return a part of the string in the range of the string designation index.
public String substring(int startIndex)public String substring(int startIndex, int endIndex)startIndex : Required. Starting index number (int type), starting from 0endIndex : Optional. End index number (int type), if omitted, return to the end of the string.
public class Test {public static void main(String[] args) {String str = "code-journey.com";System.out.println(hz.substring(0,4)); // result: codeSystem.out.println(hz.substring(5)); // result: : journey.comSystem.out.println(hz.substring(0)); // result: : code-journey.comSystem.out.println(hz.substring(5,20)); // result : (fail) StringIndexOutOfBoundsException}}