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

Question about String Concatenation

+7 votes
Is it okay if we add a char to a String?
asked Oct 12, 2017 in CSC 211 (F17) by Tiffany Nguyen (100 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, 2017 by Forrest Stonedahl (100 points)
selected Oct 16, 2017 by Tiffany Nguyen
+3 votes

Yes, it would become one string.

For example:

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

Will print out



answered Oct 12, 2017 by Minh Ta (100 points)