Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
My code:
Java
String o = "56";
String hello = "Rudra";
System.out.println(o.concat(hello));


What I have tried:

Why it says:
56Rudra but not 56 Rudra
Posted
Updated 21-Jul-23 2:29am
v2

Because you are concatenating "56" o with "Rudra" hello - you have not included any spaces

In fact - look at the solution to your earlier question How to add space between this output?[^]
 
Share this answer
 
v2
Comments
Rudra 2023 21-Jul-23 7:28am    
I have used the concat method to add spaces only.
Richard Deeming 21-Jul-23 7:38am    
The concat method concatenates two strings. It does NOT add any space or extra characters between the two strings.
Instead of posting the same basic question again, your time would be better spent actually learning the language. Go to Java Tutorials Learning Paths[^], where everything is clearly explained.
 
Share this answer
 
Hint: read the documentation String (Java Platform SE 8 )[^].
 
Share this answer
 
Comments
Graeme_Grant 21-Jul-23 7:34am    
Class is out
To add to the other's answers, Java includes a join method that can concatenate any number of strings with a separator string between each:
Java
System.out.println(String.join(" ", "Hello", "World"));

Result
Hello World
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900