Wednesday 13 March 2013

java.lang String


java.lang
String

Declaration
public final class String
java.lang.Object
|
+--java.lang.String
Description
The String class represents character strings. All string literals in Java programs, such as “abc”, are
implemented as instances of this class.
Strings are constant; their values cannot be changed after they are created. String buffers support mutable
strings. Because String objects are immutable they can be shared. For example:
String str = “abc”;
is equivalent to:
char data[] = {'a', 'b', 'c'};
String str = new String(data);
Here are some more examples of how strings can be used:
System.out.println(“abc”);
String cde = “cde”;
System.out.println(“abc” + cde);
String c = “abc”.substring(2,3);
String d = cde.substring(1, 2);
The class String includes methods for examining individual characters of the sequence, for comparing
strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters
translated to uppercase or to lowercase.
The Java language provides special support for the string concatenation operator ( + ), and for conversion of
other objects to strings. String concatenation is implemented through the StringBuffer class and its
append method. String conversions are implemented through the method toString, defined by Object
and inherited by all classes in Java. For additional information on string concatenation and conversion, see
Gosling, Joy, and Steele, The Java Language Specification.
Since: JDK1.0, CLDC 1.0
See Also: Object.toString(), StringBuffer, StringBuffer.append(boolean),
StringBuffer.append(char), StringBuffer.append(char[]),
StringBuffer.append(char[], int, int), StringBuffer.append(int),
StringBuffer.append(long), StringBuffer.append(Object),
StringBuffer.append(String)


Constructors
String()
String(byte[] bytes)
String(byte[] bytes, int off, int len)
String(byte[] bytes, int off, int len, String enc)
String(byte[] bytes, String enc)
String(char[] value)
String(char[] value, int offset, int count)
String(String value)
String(StringBuffer buffer)
Methods
char charAt(int index)
int compareTo(String anotherString)
String concat(String str)
boolean endsWith(String suffix)
boolean equals(Object anObject)
boolean equalsIgnoreCase(String anotherString)
byte[] getBytes()
byte[] getBytes(String enc)
void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
int hashCode()
int indexOf(int ch)
int indexOf(int ch, int fromIndex)
int indexOf(String str)
int indexOf(String str, int fromIndex)
String intern()
int lastIndexOf(int ch)
int lastIndexOf(int ch, int fromIndex)
int length()
boolean regionMatches(boolean ignoreCase, int toffset, String other,
int ooffset, int len)
String replace(char oldChar, char newChar)
boolean startsWith(String prefix)
boolean startsWith(String prefix, int toffset)
String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
char[] toCharArray()
String toLowerCase()
String toString()
String toUpperCase()
String trim()
static String valueOf(boolean b)
static String valueOf(char c)
static String valueOf(char[] data)
static String valueOf(char[] data, int offset, int count)
static String valueOf(double d)
static String valueOf(float f)
static String valueOf(int i)
static String valueOf(long l)
static String valueOf(Object obj)


Methods inherited from class Object
getClass(), notify(), notifyAll(), wait(), wait(), wait()


Constructors
String()
Declaration:
public String()
Description:
Initializes a newly created String object so that it represents an empty character sequence.
String(String)
Declaration:
public String(java.lang.String value)
Description:
Initializes a newly created String object so that it represents the same sequence of characters as the
argument; in other words, the newly created string is a copy of the argument string.
Parameters:
value - a String.
String(char[])
Declaration:
public String(char[] value)
Description:
Allocates a new String so that it represents the sequence of characters currently contained in the
character array argument. The contents of the character array are copied; subsequent modification of the
character array does not affect the newly created string.
Parameters:
value - the initial value of the string.
Throws:
NullPointerException - if value is null.
String(char[], int, int)
Declaration:
public String(char[] value, int offset, int count)
Description:
Allocates a new String that contains characters from a subarray of the character array argument. The
offset argument is the index of the first character of the subarray and the count argument specifies the
length of the subarray. The contents of the subarray are copied; subsequent modification of the character
array does not affect the newly created string.


String(byte[], int, int, String)

Parameters:
value - array that is the source of characters.
offset - the initial offset.
count - the length.
Throws:
IndexOutOfBoundsException - if the offset and count arguments index characters outside
the bounds of the value array.
NullPointerException - if value is null.
String(byte[], int, int, String)
Declaration:
public String(byte[] bytes, int off, int len, java.lang.String enc)
throws UnsupportedEncodingException
Description:
Construct a new String by converting the specified subarray of bytes using the specified character
encoding. The length of the new String is a function of the encoding, and hence may not be equal to the
length of the subarray.
Parameters:
bytes - The bytes to be converted into characters
off - Index of the first byte to convert
len - Number of bytes to convert
enc - The name of a character encoding
Throws:
java.io.UnsupportedEncodingException - If the named encoding is not supported
Since: JDK1.1
String(byte[], String)
Declaration:
public String(byte[] bytes, java.lang.String enc)
throws UnsupportedEncodingException
Description:
Construct a new String by converting the specified array of bytes using the specified character encoding.
The length of the new String is a function of the encoding, and hence may not be equal to the length of
the byte array.
Parameters:
bytes - The bytes to be converted into characters
enc - The name of a supported character encoding
Throws:
java.io.UnsupportedEncodingException - If the named encoding is not supported
Since: JDK1.1

String(byte[], int, int)
Declaration:
public String(byte[] bytes, int off, int len)
Description:
Construct a new String by converting the specified subarray of bytes using the platform’s default
character encoding. The length of the new String is a function of the encoding, and hence may not be
equal to the length of the subarray.
Parameters:
bytes - The bytes to be converted into characters
off - Index of the first byte to convert
len - Number of bytes to convert
Since: JDK1.1
String(byte[])
Declaration:
public String(byte[] bytes)
Description:
Construct a new String by converting the specified array of bytes using the platform’s default character
encoding. The length of the new String is a function of the encoding, and hence may not be equal to the
length of the byte array.
Parameters:
bytes - The bytes to be converted into characters
Since: JDK1.1
String(StringBuffer)
Declaration:
public String(java.lang.StringBuffer buffer)
Description:
Allocates a new string that contains the sequence of characters currently contained in the string buffer
argument. The contents of the string buffer are copied; subsequent modification of the string buffer does not
affect the newly created string.
Parameters:
buffer - a StringBuffer.
Throws:
NullPointerException - If buffer is null.








No comments:

Post a Comment