public final class String extends Object implements CharSequence, Comparable<String>
Constructor and Description |
---|
String() |
String(byte[] b)
Create a String from a byte array
|
String(byte[] b,
int off,
int len)
Create a String from a byte array
|
String(byte[] b,
int off,
int len,
String charset)
Create a String from a byte array
|
String(byte[] b,
String charset)
Create a String from a byte array
|
String(char[] c)
Create a String from a character array
|
String(char[] c,
int off,
int len)
Create a String from a character array.
|
String(int[] codePoints,
int off,
int len) |
String(String s) |
String(StringBuffer sb) |
String(StringBuilder sb) |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index)
Return the character at the given index
|
int |
codePointAt(int index) |
int |
codePointBefore(int index) |
int |
codePointCount(int begin,
int end) |
int |
compareTo(String str)
Compares this with another Object.
|
int |
compareToIgnoreCase(String str)
Compares this String and another String (case insensitive).
|
String |
concat(String s) |
boolean |
contains(CharSequence s)
Returns true iff this String contains the sequence of Characters
described in s.
|
boolean |
contentEquals(CharSequence s) |
boolean |
contentEquals(StringBuffer sb) |
static String |
copyValueOf(char[] data) |
static String |
copyValueOf(char[] data,
int off,
int len) |
boolean |
endsWith(String suffix)
Predicate which determines if this String ends with a given suffix.
|
boolean |
equals(Object other)
Compares the String with an Object
|
boolean |
equalsIgnoreCase(String s) |
static String |
format(String format,
Object... args) |
byte[] |
getBytes() |
void |
getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin) |
byte[] |
getBytes(String charset)
Get bytes in US Acsii
|
void |
getChars(int start,
int end,
char[] buffer,
int off) |
int |
hashCode()
Special version of hash that returns the same value the same String
values
|
int |
indexOf(int ch)
Find the index of a character.
|
int |
indexOf(int ch,
int fromIndex)
Returns the index within this string of the first occurrence of the
specified character, starting the search at the specified index.
|
int |
indexOf(String str)
Finds the location of a string within this string
|
int |
indexOf(String str,
int fromIndex)
Find location of String starting at a given index
|
String |
intern() |
boolean |
isEmpty()
Returns true, if and only if this string is of zero length.
|
int |
lastIndexOf(int ch) |
int |
lastIndexOf(int ch,
int fromIndex) |
int |
lastIndexOf(String str)
Find the last occurrence of a String
|
int |
lastIndexOf(String str,
int fromIndex)
Find last occurrence of s string from a given index
|
int |
length()
Return the length of the String in characters
|
int |
offsetByCodePoints(int idx,
int codePointCount) |
boolean |
regionMatches(boolean ignoreCase,
int toffset,
String other,
int ooffset,
int len)
Tests if two string regions are equal.
|
boolean |
regionMatches(int toffset,
String other,
int ooffset,
int len)
Tests if two string regions are equal.
|
String |
replace(char oldChar,
char newChar) |
String[] |
split(String seperators)
Split this string around the matches of a character string.
|
boolean |
startsWith(String s)
Predicate which determines if this String starts with a given prefix.
|
boolean |
startsWith(String s,
int begin) |
CharSequence |
subSequence(int start,
int end)
Returns a new
CharSequence of the indicated range. |
String |
substring(int start)
Return substring from starting position to the end of the String
|
String |
substring(int start,
int end)
Return substring from starting index to position before end index
|
char[] |
toCharArray()
Converts the String into an array of characters
|
String |
toLowerCase() |
String |
toString()
Returns itself.
|
String |
toUpperCase() |
String |
trim() |
static String |
valueOf(boolean b) |
static String |
valueOf(char c) |
static String |
valueOf(char[] c) |
static String |
valueOf(char[] c,
int start,
int length) |
static String |
valueOf(double d) |
static String |
valueOf(float f) |
static String |
valueOf(int i) |
static String |
valueOf(long i) |
static String |
valueOf(Object aObj)
Converts an Object to a String
|
public String()
public String(byte[] b)
b
- the byte arraypublic String(byte[] b, int off, int len)
b
- the byte arraypublic String(byte[] b, int off, int len, String charset)
b
- the byte arraycharset
- ignored - assumed to be US ASCIIpublic String(byte[] b, String charset)
b
- the byte arraycharset
- ignored - assumed to be US ASCIIpublic String(char[] c)
c
- the character arraypublic String(char[] c, int off, int len)
c
- the character arrayoff
- the offset - usually 0len
- the length of the String - must not be greater than c.lengthpublic String(int[] codePoints, int off, int len)
public String(String s)
public String(StringBuffer sb)
public String(StringBuilder sb)
public char charAt(int index)
charAt
in interface CharSequence
index
- the index to retrieve frompublic int codePointAt(int index)
public int codePointBefore(int index)
public int codePointCount(int begin, int end)
public int compareTo(String str)
Comparable
compareTo
in interface Comparable<String>
str
- the object to compare withpublic int compareToIgnoreCase(String str)
str
- the string to compare againstpublic boolean contains(CharSequence s)
s
- the CharSequencepublic boolean contentEquals(CharSequence s)
public boolean contentEquals(StringBuffer sb)
public static String copyValueOf(char[] data)
public static String copyValueOf(char[] data, int off, int len)
public boolean endsWith(String suffix)
suffix
- String to compareNullPointerException
- if suffix is nullpublic boolean equals(Object other)
public boolean equalsIgnoreCase(String s)
public byte[] getBytes()
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
public byte[] getBytes(String charset)
charset
- ignoredpublic void getChars(int start, int end, char[] buffer, int off)
public int hashCode()
public int indexOf(int ch)
ch
- The character to find.public int indexOf(int ch, int fromIndex)
ch
- a character (Unicode code point).fromIndex
- the index to start the search from.fromIndex
, or -1
if
the character does not occur.public int indexOf(String str)
str
- the Stringpublic int indexOf(String str, int fromIndex)
str
- the StringfromIndex
- the starting positionpublic String intern()
public boolean isEmpty()
public int lastIndexOf(int ch)
public int lastIndexOf(int ch, int fromIndex)
public int lastIndexOf(String str)
str
- the Stringpublic int lastIndexOf(String str, int fromIndex)
str
- the StringfromIndex
- the starting pointpublic int length()
length
in interface CharSequence
public int offsetByCodePoints(int idx, int codePointCount)
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent character sequences that are the same, ignoring case if and only if ignoreCase is true. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true:
this.charAt(toffset+k) != other.charAt(ooffset+k)
and:Character.toLowerCase(this.charAt(toffset+k)) != Character.toLowerCase(other.charAt(ooffset+k))
Character.toUpperCase(this.charAt(toffset+k)) != Character.toUpperCase(other.charAt(ooffset+k))
ignoreCase
- if true
, ignore case when comparing
characters.toffset
- the starting offset of the subregion in this
string.other
- the string argument.ooffset
- the starting offset of the subregion in the string
argument.len
- the number of characters to compare.true
if the specified subregion of this string
matches the specified subregion of the string argument;
false
otherwise. Whether the matching is exact
or case insensitive depends on the ignoreCase
argument.public boolean regionMatches(int toffset, String other, int ooffset, int len)
A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true:
toffset
- the starting offset of the subregion in this string.other
- the string argument.ooffset
- the starting offset of the subregion in the string
argument.len
- the number of characters to compare.true
if the specified subregion of this string
exactly matches the specified subregion of the string argument;
false
otherwise.public String replace(char oldChar, char newChar)
public String[] split(String seperators)
seperators
- string to matchpublic boolean startsWith(String s)
NullPointerException
- if prefix is nullstartsWith(String, int)
public boolean startsWith(String s, int begin)
public CharSequence subSequence(int start, int end)
CharSequence
CharSequence
of the indicated range.subSequence
in interface CharSequence
start
- the start index (inclusive)end
- the end index (exclusive)public String substring(int start)
start
- the starting positionpublic String substring(int start, int end)
start
- the start indexend
- the end index (not included)public char[] toCharArray()
public String toLowerCase()
public String toString()
toString
in interface CharSequence
toString
in class Object
public String toUpperCase()
public String trim()
public static String valueOf(boolean b)
public static String valueOf(char c)
public static String valueOf(char[] c)
public static String valueOf(char[] c, int start, int length)
public static String valueOf(double d)
public static String valueOf(float f)
public static String valueOf(int i)
public static String valueOf(long i)