public final class String extends Object implements CharSequence, Comparable
As with all classes in the ewe.lang package, you can't reference the String class using the full specifier of ewe.lang.String. The ewe.lang package is implicitly imported. Instead, you should simply access the String class like this:
String s = new String("Hello");
Constructor and Description |
---|
String()
Creates an empty string.
|
String(byte[] bytes) |
String(byte[] bytes,
int start,
int length) |
String(byte[] b,
int hibyte,
int offset,
int count)
Deprecated.
|
String(byte[] b,
int offset,
int count,
String encoding) |
String(byte[] b,
String encoding) |
String(char[] c)
Creates a string from the given character array.
|
String(char[] c,
int offset,
int count)
Creates a string from a portion of the given character array.
|
String(String s)
Creates a copy of the given string.
|
String(StringBuffer buffer) |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int i)
Returns the character at the given position.
|
int |
compareTo(Object other)
Compare this object with another.
|
int |
compareTo(String other) |
int |
compareToIgnoreCase(String other) |
String |
concat(String s)
Concatenates the given string to this string and returns the result.
|
boolean |
contains(CharSequence s)
Returns true if and only if this string contains the specified
sequence of char values.
|
static String |
copyValueOf(char[] data) |
static String |
copyValueOf(char[] data,
int start,
int length) |
boolean |
endsWith(String other) |
boolean |
equals(Object obj)
Returns if this object is considered equal to the other object.
|
boolean |
equalsIgnoreCase(String other) |
byte[] |
getBytes()
Convert the characters into bytes according to the default enocoding format.
|
void |
getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
Deprecated.
Use getBytes().
|
byte[] |
getBytes(String encoding)
Convert the characters into bytes according to the specified enocoding format.
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin) |
int |
hashCode()
Returns a hashCode for the object.
|
int |
indexOf(int ch) |
int |
indexOf(int ch,
int start) |
int |
indexOf(String other) |
int |
indexOf(String other,
int start) |
String |
intern()
Returns a canonical representation for the string object.
|
int |
lastIndexOf(int ch) |
int |
lastIndexOf(int ch,
int start) |
int |
lastIndexOf(String other) |
int |
lastIndexOf(String other,
int start) |
int |
length()
Returns the length of the string in characters.
|
boolean |
regionMatches(boolean ignoreCase,
int toffset,
String other,
int oofset,
int len) |
boolean |
regionMatches(int toffset,
String other,
int oofset,
int len) |
String |
replace(char oldChar,
char newChar) |
String |
replace(CharSequence target,
CharSequence replacement)
Returns a string that is this string with all instances of the sequence
represented by
target replaced by the sequence in
replacement . |
String[] |
split(String regex)
Calls split(regex,0)
|
String[] |
split(String regex,
int limit)
Splits this string around matches of the given regular expression.
|
boolean |
startsWith(String prefix)
Returns true if the given string is equal to this string and false
otherwise.
|
boolean |
startsWith(String prefix,
int offset) |
CharSequence |
subSequence(int start,
int end) |
String |
substring(int start)
Get a substring from the specified index to the end of the string.
|
String |
substring(int start,
int end)
Returns a substring of the string.
|
char[] |
toCharArray()
Returns this string as a character array.
|
String |
toLowerCase() |
String |
toLowerCase(Locale locale) |
String |
toString()
Returns this string.
|
String |
toUpperCase() |
String |
toUpperCase(Locale locale) |
String |
trim() |
static String |
valueOf(boolean b)
Converts the given boolean to a String.
|
static String |
valueOf(char c)
Converts the given char to a String.
|
static String |
valueOf(char[] data) |
static String |
valueOf(char[] data,
int start,
int length) |
static String |
valueOf(double d) |
static String |
valueOf(float f)
Converts the given float to a String.
|
static String |
valueOf(int i)
Converts the given int to a String.
|
static String |
valueOf(long l) |
static String |
valueOf(Object obj) |
public String()
public String(String s)
public String(char[] c)
public String(char[] c, int offset, int count)
c
- the character arrayoffset
- the position of the first character in the arraycount
- the number of characterspublic String(byte[] b, int offset, int count, String encoding) throws UnsupportedEncodingException
UnsupportedEncodingException
public String(byte[] b, String encoding) throws UnsupportedEncodingException
UnsupportedEncodingException
public String(byte[] b, int hibyte, int offset, int count)
b
- offset
- count
- hibyte
- public String(byte[] bytes)
public String(byte[] bytes, int start, int length)
public String(StringBuffer buffer)
public int length()
length
in interface CharSequence
public char charAt(int i)
charAt
in interface CharSequence
public String concat(String s)
public char[] toCharArray()
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
public static String copyValueOf(char[] data, int start, int length)
public static String copyValueOf(char[] data)
public static String valueOf(char[] data)
public static String valueOf(char[] data, int start, int length)
public static String valueOf(boolean b)
public static String valueOf(char c)
public static String valueOf(int i)
public static String valueOf(float f)
public static String valueOf(double d)
public static String valueOf(long l)
public String toString()
toString
in interface CharSequence
toString
in class Object
public String substring(int start, int end)
string.substring(4, 6);a string created from characters 4 and 5 will be returned.
start
- the first character of the substringend
- the character after the last character of the substringpublic String substring(int start)
public boolean startsWith(String prefix)
public boolean startsWith(String prefix, int offset)
public String replace(char oldChar, char newChar)
public boolean equals(Object obj)
Object
public boolean equalsIgnoreCase(String other)
public boolean endsWith(String other)
public int indexOf(String other)
public int indexOf(String other, int start)
public int lastIndexOf(String other)
public int lastIndexOf(String other, int start)
public int indexOf(int ch)
public int indexOf(int ch, int start)
public int lastIndexOf(int ch)
public int lastIndexOf(int ch, int start)
public int compareTo(String other)
public int compareToIgnoreCase(String other)
public String trim()
public String toUpperCase()
public String toLowerCase()
public int hashCode()
Object
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int oofset, int len)
public boolean regionMatches(int toffset, String other, int oofset, int len)
public byte[] getBytes()
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
srcBegin
- the start index.srcEnd
- the index after the final character.dst
- the destination byte array.dstBegin
- the dest location.public byte[] getBytes(String encoding) throws UnsupportedEncodingException
encoding
- the name of the encoding scheme.UnsupportedEncodingException
- if the encoding is not supported.public String intern()
A pool of strings, initially empty, is maintained privately by the class String. When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.
All literal strings and string-valued constant expressions are interned. String literals are defined in ยง3.10.5 of the Java Language Specification
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public int compareTo(Object other)
Comparable
compareTo
in interface Comparable
public boolean contains(CharSequence s)
s
- the sequence to search fors
, false otherwiseNullPointerException
- if s
is null
public String replace(CharSequence target, CharSequence replacement)
target
replaced by the sequence in
replacement
.target
- the sequence to be replacedreplacement
- the sequence used as the replacementpublic String[] split(String regex, int limit)
The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.
The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
The string "boo:and:foo", for example, yields the following results with these parameters:
Regex Limit Result : 2 { "boo", "and:foo" } : 5 { "boo", "and", "foo" } : -2 { "boo", "and", "foo" } o 5 { "b", "", ":and:f", "", "" } o -2 { "b", "", ":and:f", "", "" } o 0 { "b", "", ":and:f" }
regex
- the delimiting regular expressionlimit
- the result threshold, as described abovePatternSyntaxException
- if the regular expression's syntax is invalid