• 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

help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given a string constructed by calling s = new String(“xyzzy” ) ,
which of the calls listed below modify the string? (Choose all that
apply.)
A. s.append(“aaa” ) ;
B. s.trim();
C. s.substring(3);
D. s.replace(‘z’, ‘a’ ) ;
E. s.concat(s);
F. None of the above
why select "f".
can anyone tell me?
thx.
Edited to try to get rid of winkies - Barry
[ April 18, 2003: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
None of the methods modify the original string, they all create new strings from the original string. It is very important to undestand that strings cannot be changed, they are said to be "immutable".
 
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was a bit of a trick question though don't you think?


None of the methods modify the original string, they all create new strings from the original string.


If I put a CD palyer (in addition to the stock AM radio) in my otherwise 'stock' 1957 Chevy; did I 'modify' or 'change' it by creating something different from the original, than the original? Semantics I know, but it's those type of questions (on tests especially ) that seemingly are there merely to trip you up.
doco
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


... that seemingly are there merely to trip you up


I don't think that test designers are the evil deviants that many of us feel they are. Questions such as this one are designed to test your knowledge of immutability and understand its consequenses. Immutability for objects like Strings and the value wrappers such as Integer, Long etc. makes a lot of sense. Object identity in these cases makes little sense, so it is easy to cache those objects or implement the Flyweight pattern using them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic