Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Question about String Concatenation

+6 votes
Is it okay if we add a char to a String?
asked Oct 12 in CSC 211 (F17) by Tiffany Nguyen (2,268 points)
Note: sometimes it's fun to just try these things yourself in Eclipse, and see what happens!

2 Answers

+1 vote
Best answer

Yes, String + char works fine... but be careful about char + char .

'A' + 'B'

will turn into 65 + 66 (the ASCII code values for the characters) = 131, not "AB".

answered Oct 13 by Forrest Stonedahl (8,538 points)
selected 4 days ago by Tiffany Nguyen
+3 votes

Yes, it would become one string.

For example:

System.out.println("emu" + 's');

Will print out



answered Oct 12 by Minh Ta (5,381 points)