Skip to main content
added 4 characters in body
Source Link
MrSmith42
  • 10.2k
  • 6
  • 41
  • 52

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

And, String.valueOf(x) calls the toString() method on your StringBuilder.

public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); } 

}

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

And, String.valueOf(x) calls the toString() method on your StringBuilder.

public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); 

}

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

And, String.valueOf(x) calls the toString() method on your StringBuilder.

public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); } 

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

So you seeAnd, String.valueOf(x) calls the toString() method on your StringBuilder.

public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); 

}

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

So you see String.valueOf(x) calls the toString() method on your StringBuilder.

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

And, String.valueOf(x) calls the toString() method on your StringBuilder.

public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); 

}

Source Link
MrSmith42
  • 10.2k
  • 6
  • 41
  • 52

You need to look what System.out.println(sb); actually does. It calls in class java.io.PrintStream this method. (because a StringBuilder extends Object)

 public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } 

So you see String.valueOf(x) calls the toString() method on your StringBuilder.