When appending the subset of a String to a String object, the last position in the number of characters specified by the append statement is NOT included as part of the return object. However, when appending the subset of an char Array to a char Array object, the last position in the number of characters specified by the append statement is included as part of the return object. Why is this?
Example -
class String {
public static void main(String args[]) {
StringBuilder sb = new StringBuilder();
String name = "Java7";
sb.append(name, 1,3);
System.out.println(sb);
}
}
/* result is:
av
*/
class char {
public static void main(String args[]) {
StringBuilder sb = new StringBuilder();
char[] name = {'J', 'A', 'V', 'A', '7'};
sb.append(name, 1,3);
System.out.println(sb);
}
}
/* result is:
AVA
*/
Copyright License:
Author:「Michael」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/23353926/java-append-method-string-vs-stringbuilder