A String is a
sequence of characters, numbers, alphabets and symbols. The String class in
java.util package. The String class in java provides number of methods for
string manipulation.
Java supports direct
string concatenation with “+” symbol, without use of any other method. A String
is always read-only and once it is created it cannot be modified.
Creating a string is
very simple. Just enclose the string in double quotes and assign it to a
literal using assignment operator. String creation through assignment operator
does requires new keyword.
Example:
String
str=”New String”;
String
str1=”Hello Java”;
The String class
have 13 constructors overloaded and having different parameters.
- String()
- String(byte[] bytes)
- String(byte[] ascii, int hibyte)
- String(byte[] bytes, int offset, int length)
- String(byte[] ascii, int hibyte, int offset, int count)
- String(byte[] bytes, int offset, int length, String charsetName)
- String(byte[] bytes, String charsetName)
- String(char[] value)
- String(char[] value, int offset, int count)
- String(int[] codePoints, int offset, int count)
- String(String original)
- String(StringBuffer buffer)
- String(StringBuilder builder)
You can create sting
string using any of the above constructor.
Example :
String str1 = new String();
String str2=new String(”Hello Java”);
String str3=new String(str2);
char
ch[]={‘H’,’E’,’L’,’L’,’O’};
String str4=new String(ch);
String is one of the
most commonly used class in java.
No comments:
Post a Comment