Creating strings:
String greeting = "Hello World";
public class StringDemo{ public static void main(String[] args) { char[] helloArray={'he','e','l','l','o','.'}; String helloString=new String(helloArray); System.out.println(helloString); } }
output: hello
StringBuffer:
public StringBuffer append append(String s)
public stringBuffer append(boolean b)
public StringBuffer append(char c)
replace(),delete(), reverse(),capacity(),length(),setCharAt(int index,char ch),setLength(),String subString(int start),String subString(int start,int end)
one example in buffer class:
length() and capacity() method
public class StringBufferDemo { public static void main(String[] args) { StringBuffer sb=new StringBuffer("Hello"); System.out.println("buffer = "+sb); System.out.println("length = "+sb.length()); System.out.println("capacity = "+sb.capacity()); } }
output:
buffer = Hello length = 5 capacity = 21
For more example:
I will see in future
– Java the complete reference(Best examples here)
– Oracle Java Library
– Android Reference
– Tutorials point for explanation