What is the String + operator?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What is the String + operator?

Rating:

The + operator concatenates two strings, producing a new String object as the result. For example,

String amt = "50";
String s = "John gave me " + amt + "dollars";
System.out.println(s);


This code will display the string "John gave me 50 dollars".

The + operator may also be used to concatenate a string with other data types. For example,

int amt = 50;
String s = "John gave me" + amt + "dollars";
System.out.println(s);


This code will display the string "John gave me 50 dollars". In this case, the variable amt is declared as int rather than String, but the output produced is the same. This is because the int value contained in the variable amt is automatically converted to String type, and then the + operator concatenates the two strings.


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.