Posts

Showing posts from July 1, 2010

How to concat or add two String in java example

public class Test {         public static void main(String[] args) {                    String st = new String("Test String Here");             String st1 = new String("Second Test String Here");             String st2 = st.concat(st1);                         System.out.println(st2);         } }

what is StringIndexOutOfBoundsException in java code example

StringIndexOutOfBoundsException :- StringIndexOutOfBoundsException is thrown by the String class, if index in the string is passing greater then the string size or negative value of index in string. Example:- public class Test {         public static void main(String[] args) {                              

CharSequence java - What is CharSequence in java code example

public class Test {         public static void main(String[] args) {                                 StringBuffer stringBuffer = new StringBuffer ("Hello World");                            CharSequence charSequence = stringBuffer;               // print charSequence               System.out.println(charSequence);               // Append first in StringBuffer               stringBuffer.append(" First Append");               System.out.println(ch...

StringBuilder java - what is StringBuilder in java

StringBuilder java :- 1) StringBuilder class is like same as String. 2) StringBuilder class is not thread-safe. 3) StringBuilder class is mutable sequence of characters. 4) Main method in StringBuilder class are append and insert method. 5) Through the insert method you can insert string after any index of the string. 6) There are four constructors in StringBuilder class.     public StringBuilder()      public StringBuilder(int capacity)     public StringBuilder(String str)     public StringBuilder(CharSequence seq) Note: majaor different between StringBuilder and StringBuffer is       StringBuffer is thread-safe and StringBuilder is not thread-safe

StringBuffer java - what is StringBuffer in java

StringBuffer java :- 1) StringBuffer class is like same as String. 2) StringBuffer class is thread-safe means method are synchronized. 3) StringBuffer class is mutable sequence of characters. 4) Main method in StringBuffer class are append and insert method. 5) Through the insert method you can insert string after any index of the string. 6) There are four constructors in StringBuffer class.     public StringBuffer()      public StringBuffer(int capacity)     public StringBuffer(String str)     public StringBuffer(CharSequence seq)

String java - What is String in java

String java :- 1) Many charactors are made a string. 2) String are constants. 3) if string is created, value of String can not be changes. 4) because String are immutable. 5) A String represents UTF-16 format. Java gives the spacial way for concatenation of two or more strings String a = "xyz" char chars[] = {'x', 'y', 'z'}; String a1 = new String(data); In the above a and a1 both objects are same. String asd= "asd"; a = a+asd; System.out.println(a); 6) In the String Class public boolean contentEquals(StringBuffer sb) method has synchronized block only.

Recent Post

Recent Posts Widget