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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 09-Feb-2018 11:21:07
Advertisements