StringBuffer example
package com.ram; public class StringBuilderExample { public static void main(String[] args) { //Creates an empty StringBuilder with a capacity of 16. StringBuilder sBuilder = new StringBuilder(); sBuilder.append("There "); sBuilder.append("is "); sBuilder.append("no "); sBuilder.append("shortcut "); sBuilder.append("to success. "); sBuilder.append("Work "); sBuilder.append("Hard. "); sBuilder.append("- "); sBuilder.append("Sachin "); sBuilder.append("Tendulkar"); //To display the StringBuilder System.out.println(sBuilder); //To get the length of the StringBuilder System.out.println(sBuilder.length()); //To reverse StringBuilder System.out.println(sBuilder.reverse()); } }
Execute StringBuilderExample class and you get the below output:
There is no shortcut to success. Work Hard. - Sachin Tendulkar
62
rakludneT nihcaS - .draH kroW .sseccus ot tuctrohs on si erehT
There is no shortcut to success. Work Hard. - Sachin Tendulkar
62
rakludneT nihcaS - .draH kroW .sseccus ot tuctrohs on si erehT
No comments:
Post a Comment