Java String Class
Java String Class
Java String Class is immutable, i.e. Strings in java, once created and initialized, cannot be changed on the same reference. A java.lang.String class is final which implies no class and extend it. The java.lang.String class differs from other classes, one difference being that the String objects can be used with the += and + operators for concatenation. Two useful methods for String objects are equals( ) and substring( ). The equals( ) method is used for testing whether two Strings contain the same value. The substring( ) method is used to obtain a selected portion of a String.
char[] characters = {'a', 'b', 'C', 'D'}; StringBuffer strBuffer = new StringBuffer("abcde"); // Examples of Creation of Strings String byteStr = new String(bytes); String charStr = new String(characters); String buffStr = new String(strBuffer); System.out.println("byteStr : "+byteStr); System.out.println("charStr : "+charStr); System.out.println("buffStr : "+buffStr); } } Output byteStr : charStr : abCD buffStr : abcde