Java String Add Char Code Example

Snippet 1

  char ch='A';
String str="pple";
str= ch+str;   // str will change to "Apple" 

Snippet 2

  StringBuilder sbf = new StringBuilder("Welcome geeks!"); 
System.out.println( sbf); //will print "Welcome geeks!"

sbf.append('T'); 
System.out.println( sbf); //will print "Welcome geeks!T" 

Copyright © Code Fetcher 2020

 

 

Published

Leave a comment

Your email address will not be published. Required fields are marked *