• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Related to String

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats the different between
String s = "abc";
and
String s = new String("abc");
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
manishkumarlal cs, please check your e-mail for an important message from JavaRanch.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by manishkumarlal cs:
whats the different between
String s = "abc";
and
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!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[deleted by fbr];
[ August 30, 2007: Message edited by: Fred Rosenberger ]
 
sdit sdit
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, has not translated a moment ago
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic