Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Amith Mahalin

+ Follow
since Jan 03, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Amith Mahalin

Hi guys,

the below link is for an online Spring Framework training.

has anyone taken this online course?
If yes, do you recommend this?

10 years ago
When a call is made to the toString() method of the b1, the method calls that take place are
given below

generic : Byte.toString()-> String.valueOf(int i)-> Integer.toString(int i, int radix)
specific values: Byte.toString()-> String.valueOf(127)-> Integer.toString(127, 10)

..the thing to understand here is that everytime you make a call to the "Byte.toString()", you get a new instance of
"String" with the same value (127 to be specific)..

what happens in Integer.toString() is evident in the return statement shown here
Integer.toString(int i, int radix){
return new String(some stuff);

so,it is obvious that they(1st call to "b1.toString()" and 2nd call to "b1.toString()") are not the same. I have tried to illustrate this by tweaking your code a bit

1: Byte b1 = new Byte("127");
2: String s = b1.toString();
3: String s1 = b1.toString();
4: if(s == s1)
5: System.out.println("True");
6: else
7: System.out.println("False");

s is one instance of "String" class
s1 is another instance "String" class

so if you ask a question is (s==s1)?
the answer would be "NO"(or false) as they are pointing to different locations

hope this helps.