Forums Register Login

string

+Pie Number of slices to send: Send
Sting s = new string("abc");
a new string object is created by the above statement.

String s = "abc";
does this statement also create a new string object or it is refering to a object in the string pool?
+Pie Number of slices to send: Send
definately you can use static and native modifier are used to load any native files they may be required to run the program.
+Pie Number of slices to send: Send
hi i happened to answer the wrong question
the answer to yours question is that when we write String a=new String("abc");
a new String object is created. And when we write String b="abc"; the jvm searches in string pool and if a String object containing abc is present then it returns the reference to that string and if not present it creates a new String object and adds it to the pool and returns a reference to that obect.
Here is an example which will clear your doubt
public static void main(String a[])
{
String a=new String("abc");
String b="abc";
String c="abc";
System.out.print(a==b);//prints false
System.out.print(a==c);//prints false
System.out.print(c==b);//prints true
System.out.print(a.equals(b));//prints true
System.out.print(a.equals(c));//prints true
System.out.print(c.equals(b));//prints true
}
+Pie Number of slices to send: Send
 

Originally posted by arivu mathi:
Sting s = new string("abc");
a new string object is created by the above statement.

String s = "abc";
does this statement also create a new string object or it is refering to a object in the string pool?



I think you have created two thread with same question but in different language..... Didn't you check out this one...

String Object.

One more thing to notice to all moderators..

Well the question is different then the reply of Rohit Suman as

Originally posted by Rohit Suman:
[Q]definately you can use static and native modifier are used to load any native files they may be required to run the program
[/Q]




Earlier when I check this thread the Name of this thread was "static", but now it has been changed to "String".

Could you please justify.
+Pie Number of slices to send: Send
Rohit wrote:

hi i happened to answer the wrong question



No you answered the correct question There was a topic about "static" and "native". The bulletin board seems to be a little confused and mixing stuff up today - we are investigating the problem.
+Pie Number of slices to send: Send
yes i think so when i got the question of static and native i posted the reply for that and the answer to that question appeared somewhere else.
please buy my thing and then I'll have more money:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 606 times.
Similar Threads
Urgent String question
why we r not using 'new' for String declaration
Confused about string objects
q on garbage collection
Query about String ??
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:11:32.