String

Name

String

Synopsis

Description

The String class represents sequences of characters. Once a String object is created, it is immutable. In other words, the sequence of characters that a String represents cannot be changed after it is created. The StringBuffer class, on the other hand, represents a sequence of characters that can be changed. StringBuffer objects are used to perform computations on String objects.

The String class includes a number of utility methods, such as methods for fetching individual characters or ranges of contiguous characters, for translating characters to upper- or lowercase, for searching strings, and for parsing numeric values in strings.

String literals are compiled into String objects. Where a String literal appears in an expression, the compiled code contains a String object. If s is declared as String, the following two expressions are identical:

s.equals("ABC") "ABC".equals(s) 

The string concatenation operator implicitly creates String objects.

Class Summary

public final class java.lang.String extends java.lang.Object {
 // Constructors public String();
public String(byte[] bytes); // New in 1.1 public String(byte[] bytes, String enc); // New in 1.1 public String(byte[] bytes, int offset, int length); // New in 1.1 public String(byte[] bytes, int offset, int length, String enc); // New in 1.1 public String(byte[] lowbytes, int hibyte); // Deprecated in 1.1 public String(byte[] lowbytes, int hibyte, int offset, int count); // Deprecated in 1.1 public String(char[] value);
public String(char[] value, int offset, int;
public String(String value);
public String(StringBuffer buffer); // Class Methods public static String copyValueOf(char data[]);
public static String copyValueOf(char data[], int offset, int count);
public static String valueOf(boolean b);
public static String valueOf(char c);
public static String valueOf(char[] data);
public static String valueOf(char[] data, int offset, int count);
public static String valueOf(double d);
public static String valueOf(float f);
public static String valueOf(int i);
public static String valueOf(long l);
public static String valueOf(Object obj); // Instance Methods public char charAt(int index);
public int compareTo(String anotherString);
public String concat(String str);
public boolean endsWith(String suffix);
public boolean equals(Object anObject);
public boolean equalsIgnoreCase(String anotherString);
public byte[] getBytes(); // New in 1.1 public byte[] getBytes(String enc); // New in 1.1 public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin); // Deprecated in 1.1 public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin);
public int hashCode();
public int indexOf(int ch);
public int indexOf(int ch, int fromIndex);
public int indexOf(String str);
public int indexOf(String str, int fromIndex);
public native String intern();
public int lastIndexOf(int ch);
public int lastIndexOf(int ch, int fromIndex);
public int lastIndexOf(String str);
public int lastIndexOf(String str, int fromIndex;
public int length();
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len);
public boolean regionMatches(int toffset, String other, int ooffset, int len);
public String replace(char oldChar, char newChar);
public boolean startsWith(String prefix);
public boolean startsWith(String prefix, int toffset);
public String substring(int beginIndex);
public String substring(int beginIndex, int endIndex);
public char[] toCharArray();
public String toLowerCase();
public String toLowerCase(Locale locale); // New in 1.1 public String toString();
public String toUpperCase();
public String toUpperCase(Locale locale); // New in 1.1 public String trim();
}

Constructors

String

public String()

public String(byte[] bytes)

public String(byte[] bytes, String enc)

public String(byte[] bytes, int offset, int length)

public String(byte[] bytes, int offset, int length, String enc) 

public String(byte[] lowbytes, int hibyte)

public String(byte[] lowbytes, int hibyte, int offset, int count) 

public String(char[] value)

public String(char[] value, int offset, int count)

public String(String value)

public String(StringBuffer value)

Class Methods

copyValueOf

public static String copyValueOf(char data[])

public static String copyValueOf(char data[], int offset, int count) 

valueOf

public static String valueOf(boolean b)

public static String valueOf(char c)

public static String valueOf(char[] data)

public static String valueOf(char[] data, int offset, int count) 

public static String valueOf(double d)

public static String valueOf(float f)

public static String valueOf(int i)

public static String valueOf(long l)

public static String valueOf (Object obj)

Instance Methods

charAt

public char charAt(int index)

compareTo

public int compareTo(String anotherString)

concat

public String concat(String str)

endsWith

public boolean endsWith(String suffix)

equals

public boolean equals(Object anObject)

equalsIgnoreCase

public boolean equalsIgnoreCase(String anotherString)

getBytes

public byte[] getBytes() 

public byte[] getBytes(String enc) 

public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) 

getChars

public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 

hashCode

public int hashCode()

indexOf

public int indexOf(int ch)

public int indexOf(int ch, int fromIndex)

public int indexOf(String str)

public int indexOf(String str, int fromIndex)

intern

public native String intern()

lastIndexOf

public int lastIndexOf(int ch)

public int lastIndexOf(int ch, int fromIndex)

public int lastIndexOf(String str)

public int lastIndexOf(String str, int fromIndex)

length

public int length()

regionMatches

public boolean regionMatches(int toffset, String other, int ooffset, int len) 

public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) 

replace

public String replace(char oldChar, char newChar)

startsWith

public boolean startsWith(String prefix)

public boolean startsWith(String prefix, int toffset)

substring

public String substring(int beginIndex)

public String substring(int beginIndex, int endIndex)

toCharArray

public char[] toCharArray()

toLowerCase

public String toLowerCase()

public String toLowerCase(Locale locale)

toString

public String toString()

toUpperCase

public String toUpperCase()

public String toUpperCase(Locale locale)

trim

public String trim()

Inherited Methods

Method Inherited From Method Inherited From
clone() Object finalize() Object
getClass() Object notify() Object
notifyAll() Object wait() Object
wait(long) Object wait(long, int) Object

See Also

Character; Class; Double; Exceptions; Float; Integer; Long; Object; StringBuffer; String Concatenation Operator +; String literals