aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "string" Watch "string" New topic
Author

string

arivu mathi
Ranch Hand

Joined: Jun 26, 2006
Posts: 38
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?
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
definately you can use static and native modifier are used to load any native files they may be required to run the program.
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
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
}
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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.


The Best way to predict your future is to create it - Every great individual common man
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Rohit Suman
Ranch Hand

Joined: Sep 09, 2006
Posts: 37
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string