• 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

String concatenation

 
Ranch Hand
Posts: 47
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there;)

I am currently working my way through different Practice Questions for the OCA Exam.

I recently got this question:

Given:



Then it was asked how many objects have been created here?

The right answer was 4, but I am not quite sure why.

Am I right, that the first String-Object is created here:   String s = "Hello"; //the Object is "Hello"

Then, the second String-Object is created here:   s.concat(" World");         //the Object is " World"

Also, the third String-Object ist created here:   s.concat(" World");            //the Object is "Hello World"

At last, the fourth String-Object is created here:   s.toLowerCase();           //the Object is "hello world"

The System.out.println(s) only prints out "Hello" as String is immutable, right?

Kind regards
Florian
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Florian Jedamzik wrote:
At last, the fourth String-Object is created here:   s.toLowerCase();           //the Object is "hello world"



The String Object is actually "hello" created from this line, but the rest are correct.

Henry
 
Florian Jedamzik
Ranch Hand
Posts: 47
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks;)
reply
    Bookmark Topic Watch Topic
  • New Topic