File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Related to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Related to String " Watch "Related to String " New topic

Related to String

manishkumarlal cs

Joined: Oct 25, 2005
Posts: 11
whats the different between
String s = "abc";
String s = new String("abc");
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868

manishkumarlal cs, please check your e-mail for an important message from JavaRanch.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
lei feng

Joined: Aug 23, 2007
Posts: 26
Originally posted by manishkumarlal cs:
whats the different between
String s = "abc";
String s = new String("abc");

String is a very special class in JAVA.
String s=new String("abc"): jvm create a String Object contained "abc" then return a refrence pointed to s. SO s a refrence not a real object.
String s = "abc": jvm first use String.equals to find whether there is a same object in "string pool". if it get it, it will return this refrence pointed to s.if not, it will create a object in "string pool" and return the refrence. so you can try a experiment like this;
String s1 = new String("abc");
String s2 = new String("abc");
use "==" to see whether they are equal. and use "String.equal()" to see whether they are equal.
hope it will help you!
sdit sdit

Joined: Aug 30, 2007
Posts: 2
[deleted by fbr];
[ August 30, 2007: Message edited by: Fred Rosenberger ]
sdit sdit

Joined: Aug 30, 2007
Posts: 2
Sorry, has not translated a moment ago
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 10908

Just a reminder - this is an english language only site. I removed the text in the earlier post that was not english.

at the VERY least, if you post non-English, you must provide a translation. Even then, the non-English portion may still get deleted, as we cannot verify the translation.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Related to String
Similar Threads
what is the difference between String and other reference types?
String assignment
Difference between s = "" and new String("a")
String creation