Append a single character to a string or char array in java?


The append() method in the StringBuffer class adds the specified String to the contents of the current String buffer. Using this method you can append a single character to a string or char array in java.

Example

public class Test {
   public static void main(String args[]) {
      StringBuffer sb = new StringBuffer("Hi hello how are yo");
      sb.append("u");
      System.out.println(sb);
   }
}

Output

Hi hello how are you

Updated on: 26-Feb-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements