praveena satish

Greenhorn
+ Follow
since Jul 20, 2017
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 praveena satish

Hi i have done the below code to merge two sorted set into one,please let me know if i can optimize the code anyways.




Output:
[10, 30, 33, 40, 60, 660]
[13, 34, 40, 240, 550, 900]
[10, 13, 30, 33, 34, 40, 60, 240, 550, 660, 900]
6 years ago
Hi ,yes should have been more specific.i wanted the purpose of String intern() method.as understand from the discussion it is required for removing duplicates.

 String s="hello".concat("world");
         String s2=s.intern();  
 System.out.println(s==s2);
In the above program, seeing the first line an new instance is created in heap,but not in SCP.
in the second line, the intern method creates an instance in the SCP but returns the same reference s;

so if add few more lines of code,
                 String s="hello".concat("world");
 String s2=s.intern();
 String s3="helloworld";
 System.out.println(s==s2);//true
 System.out.println(s==s3);//true
 System.out.println(s2==s3);//true

so here should we understand it as the reference s is pointing to both the instances one in heap another one is SCP?



6 years ago
What does interning mean and why is it required
6 years ago