• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

what is this

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friendz,
can anybody explain these mentioned line of code. where i m wrong...
1. String a="one";
String b=a.concat(a); //result is oneone
if (a=="one") //true ok i m satisfied coz same string pool
if (b=="oneone") //false what is that even both b and "oneone" same string pool

2.String c=" one ";
if (c.trim()=="one") //false ??? anybody explain
if (c.trim()==c.trim()) //still false what is that ???
plz give me detail both above questions.
thanx
Aftab
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.
concat() returns a "new" string which is not in the string pool
although you can intern it into the pool.
2.
trim() also returns a new string unless there is nothing
to trim in which case, it returns the original string. In fact,
every time you call trim (as you did below), it always returns
a "new"
 
Good night. Drive safely. Here's a tiny ad for the road:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic