<aside>
💁🏻 필자는 substring() 을 subtraction(뺄셈) + string(문자열)의 합성어로 생각해 접근하겠다.
</aside>
public class SubStringDemo {
public static void main(String[] args) {
String a = "abc".substring(0);
String b = "abc".substring(1);
String c = "abc".substring(2);
String d = "abc".substring(3);
System.out.println(a); //abc
System.out.println(b); //bc
System.out.println(c); //c
System.out.println(d); //an empty string
//is equivalent to:
String abc = "abc";
String d = abc.substring(0);
String e = abc.substring(1);
String f = abc.substring(2);
System.out.println(d); //abc
System.out.println(e); //bc
System.out.println(f); //c
}
}
<aside> 💁🏻 Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.
Examples:
"unhappy".substring(2) returns "happy" "Harbison".substring(3) returns "bison" "emptiness".substring(9) returns "" (an empty string)
</aside>
<aside>
💁🏻 Returns a string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Examples:
"hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile"
</aside>
🔗 substirng(int beginIndx): https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int)