Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

String concatenation

 
Ranch Hand
Posts: 47
3
  • Mark post as helpful
  • send pies
  • 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: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks;)
 
I was her plaything! And so was this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic