• 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

mock test question on strings and stringbuffer

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 1.

Given a string constructed by calling s=new String("xyzzy");
which of the calls listed below modify the string
(choose all that apply)


1. s.append("aaa");
2. s.trim();
3. s.substring(3);
4. s.concat(s);
5. s.indexOf('y');
6. None

Question 2.

Given a string constructed by calling s=new String("xyzzy ");
which of the calls listed below modify the string
(choose all that apply)

1. s.append("aaa");
2. s.trim();
3. s.substring(3);
4. s.concat(s);
5. s.indexOf('y');
6. None


Question 3.

Given a string constructed by calling
StringBuffer s=new StringBuffer("xyzzy");
which of the calls listed below modify the string
(choose all that apply)

1. s.append("aaa");
2. s.trim();
3. s.substring(3);
4. s.concat(s);
5. s.indexOf('y');
6. None


Can any one of u tell me the answers .

Regards
Naresh
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naresh.
strings are immutable.
So if you want something extended or changed you should really make a new string object. And you need something to point to that new object.

With stringbuffers this is different.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
none of he methods in String class can alter it's content. Check for
stringbuffer class for your requirement. Looks like all 3 qns are repeating.
[ December 05, 2005: Message edited by: Enge Chall ]
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some comments on the immutabilty of strings and related items you can see at

http://www.jchq.net/certkey/0802certkey.htm
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic