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

Amith Mahalin

Greenhorn
+ Follow
since Jan 03, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
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.
http://www.springpeople.com/courses/elearning/e-sjs.php

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

Regards
Amith
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.