Android学习笔记二十八:String(示例,出错代码)

出处:http://www.apihome.cn/api/android/String.html

contains判断本字符串是否包含某个字符串,如果包含,返回true;
indexOf返回某个字符串在本字符串首次出现的位置,如果没有找到返回-1;

public static boolean containsString(String src, String dest) {
boolean flag = false;
if (src.contains(dest)) {
flag = true;
}
return flag;
}



public static boolean indexOfString(String src, String dest) {
boolean flag = false;
if (src.indexOf(dest)!=-1) {
flag = true;
}
return flag;
}

java.lang
类 String

java.lang.Object
  继承者 java.lang.String
所有已实现的接口:
Serializable, CharSequence, Comparable<String>

public final class String
    
    
     
     extends Object
    
    
    
    
     
     implements Serializable, Comparable<String>, CharSequence
    
    

An immutable sequence of characters/code units (chars). A String is represented by array of UTF-16 values, such that Unicode supplementary characters (code points) are stored/encoded as surrogate pairs via Unicode code units (char).

从以下版本开始:
Android 1.0
另请参见:
StringBuffer, StringBuilder, Charset, 序列化表格

字段摘要
static Comparator<String>CASE_INSENSITIVE_ORDER 
          A comparator ignoring the case of the characters.
 
构造方法摘要
String() 
          Creates an empty string.
String(byte[] data) 
          Converts the byte array to a string using the default encoding as specified by the file.encoding system property.
String(byte[] data, int high) 
          已过时。 Use String(byte[]) or String(byte[], String) instead.
String(byte[] data, int start, int length) 
          Converts the byte array to a string using the default encoding as specified by the file.encoding system property.
String(byte[] data, int high, int start, int length) 
          已过时。 Use String(byte[], int, int) instead.
String(byte[] data, int start, int length, String encoding) 
          Converts the byte array to a string using the specified encoding.
String(byte[] data, String encoding) 
          Converts the byte array to a string using the specified encoding.
String(char[] data) 
          Initializes this string to contain the characters in the specified character array.
String(char[] data, int start, int length) 
          Initializes this string to contain the specified characters in the character array.
String(int[] codePoints, int offset, int count) 
          Creates a String from the sub-array of Unicode code points.
String(String string) 
          Creates a String that is a copy of the specified string.
String(StringBuffer stringbuffer) 
          Creates a String from the contents of the specified StringBuffer.
String(StringBuilder sb) 
          Creates a String from the contents of the specified StringBuilder.
 
方法摘要
 charcharAt(int index) 
          Returns the character at the specified offset in this string.
 intcodePointAt(int index) 
          Retrieves the Unicode code point (character) value at the specified index.
 intcodePointBefore(int index) 
          Retrieves the Unicode code point value that precedes the specified index.
 intcodePointCount(int beginIndex, int endIndex) 
          Calculates the number of Unicode code points between beginIndex and endIndex.
 intcompareTo(String string) 
          Compares the specified string to this string using the Unicode values of the characters.
 intcompareToIgnoreCase(String string) 
          Compares the specified string to this string using the Unicode values of the characters, ignoring case differences.
 Stringconcat(String string) 
          Concatenates this string and the specified string.
 booleancontains(CharSequence cs) 
          Determines if this String contains the sequence of characters in the CharSequence passed.
 booleancontentEquals(CharSequence cs) 
          Compares a CharSequence to this String to determine if their contents are equal.
 booleancontentEquals(StringBuffer strbuf) 
          Returns whether the characters in the StringBuffer strbuf are the same as those in this string.
static StringcopyValueOf(char[] data) 
          Creates a new string containing the characters in the specified character array.
static StringcopyValueOf(char[] data, int start, int length) 
          Creates a new string containing the specified characters in the character array.
 booleanendsWith(String suffix) 
          Compares the specified string to this string to determine if the specified string is a suffix.
 booleanequals(Object object) 
          Compares the specified object to this string and returns true if they are equal.
 booleanequalsIgnoreCase(String string) 
          Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.
static Stringformat(Locale loc, String format, Object... args) 
          Returns a formatted string, using the supplied format and arguments, accordingly to the specified locale.
static Stringformat(String format, Object... args) 
          Returns a formatted string, using the supplied format and arguments, using the default locale.
 byte[]getBytes() 
          Converts this string to a byte array using the default encoding as specified by the file.encoding system property.
 voidgetBytes(int start, int end, byte[] data, int index) 
          已过时。 Use getBytes() or getBytes(String)
 byte[]getBytes(String encoding) 
          Converts this string to a byte array using the specified encoding.
 voidgetChars(int start, int end, char[] buffer, int index) 
          Copies the specified characters in this string to the character array starting at the specified offset in the character array.
 inthashCode() 
          Returns an integer hash code for this object.
 intindexOf(int c) 
          Searches in this string for the first index of the specified character.
 intindexOf(int c, int start) 
          Searches in this string for the index of the specified character.
 intindexOf(String string) 
          Searches in this string for the first index of the specified string.
 intindexOf(String subString, int start) 
          Searches in this string for the index of the specified string.
 Stringintern() 
          Searches an internal table of strings for a string equal to this string.
 intlastIndexOf(int c) 
          Searches in this string for the last index of the specified character.
 intlastIndexOf(int c, int start) 
          Searches in this string for the index of the specified character.
 intlastIndexOf(String string) 
          Searches in this string for the last index of the specified string.
 intlastIndexOf(String subString, int start) 
          Searches in this string for the index of the specified string.
 intlength() 
          Returns the size of this string.
 booleanmatches(String expr) 
          Determines whether this string matches a given regular expression.
 intoffsetByCodePoints(int index, int codePointOffset) 
          Returns the index within this object that is offset from index by codePointOffset code points.
 booleanregionMatches(boolean ignoreCase, int thisStart, String string, int start, int length) 
          Compares the specified string to this string and compares the specified range of characters to determine if they are the same.
 booleanregionMatches(int thisStart, String string, int start, int length) 
          Compares the specified string to this string and compares the specified range of characters to determine if they are the same.
 Stringreplace(char oldChar, char newChar) 
          Copies this string replacing occurrences of the specified character with another character.
 Stringreplace(CharSequence target, CharSequence replacement) 
          Copies this string replacing occurrences of the specified target sequence with another sequence.
 StringreplaceAll(String expr, String substitute) 
          Replace any substrings within this string that match the supplied regular expression expr, with the string substitute.
 StringreplaceFirst(String expr, String substitute) 
          Replace the first substring within this string that matches the supplied regular expression expr, with the string substitute.
 String[]split(String expr) 
          Splits this string using the supplied regular expression expr.
 String[]split(String expr, int max) 
          Splits this string using the supplied regular expression expr.
 booleanstartsWith(String prefix) 
          Compares the specified string to this string to determine if the specified string is a prefix.
 booleanstartsWith(String prefix, int start) 
          Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.
 CharSequencesubSequence(int start, int end) 
          Has the same result as the substring function, but is present so that string may implement the CharSequence interface.
 Stringsubstring(int start) 
          Copies a range of characters into a new string.
 Stringsubstring(int start, int end) 
          Copies a range of characters into a new string.
 char[]toCharArray() 
          Copies the characters in this string to a character array.
 StringtoLowerCase() 
          Converts the characters in this string to lowercase, using the default Locale.
 StringtoLowerCase(Locale locale) 
          Converts the characters in this string to lowercase, using the specified Locale.
 StringtoString() 
          Returns this string.
 StringtoUpperCase() 
          Converts the characters in this string to uppercase, using the default Locale.
 StringtoUpperCase(Locale locale) 
          Converts the characters in this string to uppercase, using the specified Locale.
 Stringtrim() 
          Copies this string removing white space characters from the beginning and end of the string.
static StringvalueOf(boolean value) 
          Converts the specified boolean to its string representation.
static StringvalueOf(char value) 
          Converts the specified character to its string representation.
static StringvalueOf(char[] data) 
          Creates a new string containing the characters in the specified character array.
static StringvalueOf(char[] data, int start, int length) 
          Creates a new string containing the specified characters in the character array.
static StringvalueOf(double value) 
          Converts the specified double to its string representation.
static StringvalueOf(float value) 
          Converts the specified float to its string representation.
static StringvalueOf(int value) 
          Converts the specified integer to its string representation.
static StringvalueOf(long value) 
          Converts the specified long to its string representation.
static StringvalueOf(Object value) 
          Converts the specified object to its string representation.
 
从类 java.lang.Object 继承的方法
getClass, notify, notifyAll, wait, wait, wait
 

字段详细信息

CASE_INSENSITIVE_ORDER

public static final Comparator<String> CASE_INSENSITIVE_ORDER
A comparator ignoring the case of the characters.

从以下版本开始:
Android 1.0
构造方法详细信息

String

public String()
Creates an empty string.

从以下版本开始:
Android 1.0

String

public String(byte[] data)
Converts the byte array to a string using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.

参数:
data - the byte array to convert to a string.
从以下版本开始:
Android 1.0

String

@Deprecated
public String(byte[] data,
                         int high)
已过时。  Use String(byte[]) or String(byte[], String) instead.

Converts the byte array to a string, setting the high byte of every character to the specified value.

参数:
data - the byte array to convert to a string.
high - the high byte to use.
从以下版本开始:
Android 1.0

String

public String(byte[] data,
              int start,
              int length)
Converts the byte array to a string using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.

参数:
data - the byte array to convert to a string.
start - the starting offset in the byte array.
length - the number of bytes to convert.
抛出:
IndexOutOfBoundsException - if  length < 0, start < 0 or  start + length > data.length.
从以下版本开始:
Android 1.0

String

@Deprecated
public String(byte[] data,
                         int high,
                         int start,
                         int length)
已过时。  Use String(byte[], int, int) instead.

Converts the byte array to a string, setting the high byte of every character to the specified value.

参数:
data - the byte array to convert to a string.
high - the high byte to use.
start - the starting offset in the byte array.
length - the number of bytes to convert.
抛出:
IndexOutOfBoundsException - if  length < 0, start < 0 or  start + length > data.length
从以下版本开始:
Android 1.0

String

public String(byte[] data,
              int start,
              int length,
              String encoding)
       throws UnsupportedEncodingException
Converts the byte array to a string using the specified encoding.

参数:
data - the byte array to convert to a string.
start - the starting offset in the byte array.
length - the number of bytes to convert.
encoding - the encoding.
抛出:
IndexOutOfBoundsException - if  length < 0, start < 0 or  start + length > data.length.
UnsupportedEncodingException - if  encoding is not supported.
从以下版本开始:
Android 1.0

String

public String(byte[] data,
              String encoding)
       throws UnsupportedEncodingException
Converts the byte array to a string using the specified encoding.

参数:
data - the byte array to convert to a string.
encoding - the encoding.
抛出:
UnsupportedEncodingException - if  encoding is not supported.
从以下版本开始:
Android 1.0

String

public String(char[] data)
Initializes this string to contain the characters in the specified character array. Modifying the character array after creating the string has no effect on the string.

参数:
data - the array of characters.
从以下版本开始:
Android 1.0

String

public String(char[] data,
              int start,
              int length)
Initializes this string to contain the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.

参数:
data - the array of characters.
start - the starting offset in the character array.
length - the number of characters to use.
抛出:
IndexOutOfBoundsException - if  length < 0, start < 0 or  start + length > data.length
从以下版本开始:
Android 1.0

String

public String(String string)
Creates a  String that is a copy of the specified string.

参数:
string - the string to copy.
从以下版本开始:
Android 1.0

String

public String(StringBuffer stringbuffer)
Creates a  String from the contents of the specified  StringBuffer.

参数:
stringbuffer - the buffer to get the contents from.
从以下版本开始:
Android 1.0

String

public String(int[] codePoints,
              int offset,
              int count)
Creates a  String from the sub-array of Unicode code points.

参数:
codePoints - the array of Unicode code points to convert.
offset - the inclusive index into  codePoints to begin converting from.
count - the number of elements in  codePoints to copy.
抛出:
IllegalArgumentException - if any of the elements of  codePoints are not valid Unicode code points.
IndexOutOfBoundsException - if  offset or  count are not within the bounds of  codePoints.
从以下版本开始:
Android 1.0

String

public String(StringBuilder sb)
Creates a  String from the contents of the specified  StringBuilder.

参数:
sb - the  StringBuilder to copy the contents from.
从以下版本开始:
Android 1.0
方法详细信息

charAt

public char charAt(int index)
Returns the character at the specified offset in this string.

指定者:
接口  CharSequence 中的  charAt
参数:
index - the zero-based index in this string.
返回:
the character at the index.
抛出:
IndexOutOfBoundsException - if  index < 0 or  index >= length().
从以下版本开始:
Android 1.0

compareTo

public int compareTo(String string)
Compares the specified string to this string using the Unicode values of the characters. Returns 0 if the strings contain the same characters in the same order. Returns a negative integer if the first non-equal character in this string has a Unicode value which is less than the Unicode value of the character at the same position in the specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first non-equal character in this string has a Unicode value which is greater than the Unicode value of the character at the same position in the specified string, or if the specified string is a prefix of this string.

指定者:
接口  Comparable<String> 中的  compareTo
参数:
string - the string to compare.
返回:
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
从以下版本开始:
Android 1.0

compareToIgnoreCase

public int compareToIgnoreCase(String string)
Compares the specified string to this string using the Unicode values of the characters, ignoring case differences. Returns 0 if the strings contain the same characters in the same order. Returns a negative integer if the first non-equal character in this string has a Unicode value which is less than the Unicode value of the character at the same position in the specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first non-equal character in this string has a Unicode value which is greater than the Unicode value of the character at the same position in the specified string, or if the specified string is a prefix of this string.

参数:
string - the string to compare.
返回:
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
从以下版本开始:
Android 1.0

concat

public String concat(String string)
Concatenates this string and the specified string.

参数:
string - the string to concatenate
返回:
a new string which is the concatenation of this string and the specified string.
从以下版本开始:
Android 1.0

copyValueOf

public static String copyValueOf(char[] data)
Creates a new string containing the characters in the specified character array. Modifying the character array after creating the string has no effect on the string.

参数:
data - the array of characters.
返回:
the new string.
从以下版本开始:
Android 1.0

copyValueOf

public static String copyValueOf(char[] data,
                                 int start,
                                 int length)
Creates a new string containing the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.

参数:
data - the array of characters.
start - the starting offset in the character array.
length - the number of characters to use.
返回:
the new string.
抛出:
IndexOutOfBoundsException - if  length < 0, start < 0 or  start + length > data.length.
从以下版本开始:
Android 1.0

endsWith

public boolean endsWith(String suffix)
Compares the specified string to this string to determine if the specified string is a suffix.

参数:
suffix - the suffix to look for.
返回:
true if the specified string is a suffix of this string,  false otherwise.
从以下版本开始:
Android 1.0

equals

public boolean equals(Object object)
Compares the specified object to this string and returns true if they are equal. The object must be an instance of string with the same characters in the same order.

覆盖:
类  Object 中的  equals
参数:
object - the object to compare.
返回:
true if the specified object is equal to this string,  false otherwise.
从以下版本开始:
Android 1.0
另请参见:
hashCode

equalsIgnoreCase

public boolean equalsIgnoreCase(String string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.

参数:
string - the string to compare.
返回:
true if the specified string is equal to this string,  false otherwise.
从以下版本开始:
Android 1.0

getBytes

public byte[] getBytes()
Converts this string to a byte array using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.

返回:
the byte array encoding of this string.
从以下版本开始:
Android 1.0

getBytes

@Deprecated
public void getBytes(int start,
                                int end,
                                byte[] data,
                                int index)
已过时。  Use getBytes() or getBytes(String)

Converts this string to a byte array, ignoring the high order bits of each character.

参数:
start - the starting offset of characters to copy.
end - the ending offset of characters to copy.
data - the destination byte array.
index - the starting offset in the destination byte array.
抛出:
IndexOutOfBoundsException - if  start < 0end > length()index < 0 or  end - start > data.length - index.
从以下版本开始:
Android 1.0

getBytes

public byte[] getBytes(String encoding)
                throws UnsupportedEncodingException
Converts this string to a byte array using the specified encoding.

参数:
encoding - the encoding to use.
返回:
the encoded byte array of this string.
抛出:
UnsupportedEncodingException - if the encoding is not supported.
从以下版本开始:
Android 1.0

getChars

public void getChars(int start,
                     int end,
                     char[] buffer,
                     int index)
Copies the specified characters in this string to the character array starting at the specified offset in the character array.

参数:
start - the starting offset of characters to copy.
end - the ending offset of characters to copy.
buffer - the destination character array.
index - the starting offset in the character array.
抛出:
IndexOutOfBoundsException - if  start < 0end > length()start > endindex < 0end - start > buffer.length - index
从以下版本开始:
Android 1.0

hashCode

public int hashCode()
从类 Object 复制的描述
Returns an integer hash code for this object. By contract, any two objects for which  equals(Object) returns  true must return the same hash code value. This means that subclasses of  Object usually override both methods or neither method.

覆盖:
类  Object 中的  hashCode
返回:
this object's hash code.
另请参见:
Object.equals(java.lang.Object)

indexOf

public int indexOf(int c)
Searches in this string for the first index of the specified character. The search for the character starts at the beginning and moves towards the end of this string.

参数:
c - the character to find.
返回:
the index in this string of the specified character, -1 if the character isn't found.
从以下版本开始:
Android 1.0

indexOf

public int indexOf(int c,
                   int start)
Searches in this string for the index of the specified character. The search for the character starts at the specified offset and moves towards the end of this string.

参数:
c - the character to find.
start - the starting offset.
返回:
the index in this string of the specified character, -1 if the character isn't found.
从以下版本开始:
Android 1.0

indexOf

public int indexOf(String string)
Searches in this string for the first index of the specified string. The search for the string starts at the beginning and moves towards the end of this string.

参数:
string - the string to find.
返回:
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
从以下版本开始:
Android 1.0

indexOf

public int indexOf(String subString,
                   int start)
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the end of this string.

参数:
subString - the string to find.
start - the starting offset.
返回:
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
从以下版本开始:
Android 1.0

intern

public String intern()
Searches an internal table of strings for a string equal to this string. If the string is not in the table, it is added. Returns the string contained in the table which is equal to this string. The same string object is always returned for strings which are equal.

返回:
the interned string equal to this string.
从以下版本开始:
Android 1.0

lastIndexOf

public int lastIndexOf(int c)
Searches in this string for the last index of the specified character. The search for the character starts at the end and moves towards the beginning of this string.

参数:
c - the character to find.
返回:
the index in this string of the specified character, -1 if the character isn't found.
从以下版本开始:
Android 1.0

lastIndexOf

public int lastIndexOf(int c,
                       int start)
Searches in this string for the index of the specified character. The search for the character starts at the specified offset and moves towards the beginning of this string.

参数:
c - the character to find.
start - the starting offset.
返回:
the index in this string of the specified character, -1 if the character isn't found.
从以下版本开始:
Android 1.0

lastIndexOf

public int lastIndexOf(String string)
Searches in this string for the last index of the specified string. The search for the string starts at the end and moves towards the beginning of this string.

参数:
string - the string to find.
返回:
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
从以下版本开始:
Android 1.0

lastIndexOf

public int lastIndexOf(String subString,
                       int start)
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the beginning of this string.

参数:
subString - the string to find.
start - the starting offset.
返回:
the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
从以下版本开始:
Android 1.0

length

public int length()
Returns the size of this string.

指定者:
接口  CharSequence 中的  length
返回:
the number of characters in this string.
从以下版本开始:
Android 1.0

regionMatches

public boolean regionMatches(int thisStart,
                             String string,
                             int start,
                             int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same.

参数:
thisStart - the starting offset in this string.
string - the string to compare.
start - the starting offset in the specified string.
length - the number of characters to compare.
返回:
true if the ranges of characters are equal,  false otherwise
从以下版本开始:
Android 1.0

regionMatches

public boolean regionMatches(boolean ignoreCase,
                             int thisStart,
                             String string,
                             int start,
                             int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same. When ignoreCase is true, the case of the characters is ignored during the comparison.

参数:
ignoreCase - specifies if case should be ignored.
thisStart - the starting offset in this string.
string - the string to compare.
start - the starting offset in the specified string.
length - the number of characters to compare.
返回:
true if the ranges of characters are equal,  false otherwise.
从以下版本开始:
Android 1.0

replace

public String replace(char oldChar,
                      char newChar)
Copies this string replacing occurrences of the specified character with another character.

参数:
oldChar - the character to replace.
newChar - the replacement character.
返回:
a new string with occurrences of oldChar replaced by newChar.
从以下版本开始:
Android 1.0

replace

public String replace(CharSequence target,
                      CharSequence replacement)
Copies this string replacing occurrences of the specified target sequence with another sequence. The string is processed from the beginning to the end.

参数:
target - the sequence to replace.
replacement - the replacement sequence.
返回:
the resulting string.
从以下版本开始:
Android 1.0

startsWith

public boolean startsWith(String prefix)
Compares the specified string to this string to determine if the specified string is a prefix.

参数:
prefix - the string to look for.
返回:
true if the specified string is a prefix of this string,  false otherwise
从以下版本开始:
Android 1.0

startsWith

public boolean startsWith(String prefix,
                          int start)
Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.

参数:
prefix - the string to look for.
start - the starting offset.
返回:
true if the specified string occurs in this string at the specified offset,  false otherwise.
从以下版本开始:
Android 1.0

substring

public String substring(int start)
Copies a range of characters into a new string.

参数:
start - the offset of the first character.
返回:
a new string containing the characters from start to the end of the string.
抛出:
IndexOutOfBoundsException - if  start < 0 or  start > length().
从以下版本开始:
Android 1.0

substring

public String substring(int start,
                        int end)
Copies a range of characters into a new string.

参数:
start - the offset of the first character.
end - the offset one past the last character.
返回:
a new string containing the characters from start to end - 1
抛出:
IndexOutOfBoundsException - if  start < 0start > end or  end > length().
从以下版本开始:
Android 1.0

toCharArray

public char[] toCharArray()
Copies the characters in this string to a character array.

返回:
a character array containing the characters of this string.
从以下版本开始:
Android 1.0

toLowerCase

public String toLowerCase()
Converts the characters in this string to lowercase, using the default Locale.

返回:
a new string containing the lowercase characters equivalent to the characters in this string.
从以下版本开始:
Android 1.0

toLowerCase

public String toLowerCase(Locale locale)
Converts the characters in this string to lowercase, using the specified Locale.

参数:
locale - the Locale to use.
返回:
a new string containing the lowercase characters equivalent to the characters in this string.
从以下版本开始:
Android 1.0

toString

public String toString()
Returns this string.

指定者:
接口  CharSequence 中的  toString
覆盖:
类  Object 中的  toString
返回:
this string.
从以下版本开始:
Android 1.0

toUpperCase

public String toUpperCase()
Converts the characters in this string to uppercase, using the default Locale.

返回:
a new string containing the uppercase characters equivalent to the characters in this string.
从以下版本开始:
Android 1.0

toUpperCase

public String toUpperCase(Locale locale)
Converts the characters in this string to uppercase, using the specified Locale.

参数:
locale - the Locale to use.
返回:
a new string containing the uppercase characters equivalent to the characters in this string.
从以下版本开始:
Android 1.0

trim

public String trim()
Copies this string removing white space characters from the beginning and end of the string.

返回:
a new string with characters  <= \\u0020 removed from the beginning and the end.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(char[] data)
Creates a new string containing the characters in the specified character array. Modifying the character array after creating the string has no effect on the string.

参数:
data - the array of characters.
返回:
the new string.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(char[] data,
                             int start,
                             int length)
Creates a new string containing the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.

参数:
data - the array of characters.
start - the starting offset in the character array.
length - the number of characters to use.
返回:
the new string.
抛出:
IndexOutOfBoundsException - if  length < 0start < 0 or  start + length > data.length
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(char value)
Converts the specified character to its string representation.

参数:
value - the character.
返回:
the character converted to a string.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(double value)
Converts the specified double to its string representation.

参数:
value - the double.
返回:
the double converted to a string.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(float value)
Converts the specified float to its string representation.

参数:
value - the float.
返回:
the float converted to a string.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(int value)
Converts the specified integer to its string representation.

参数:
value - the integer.
返回:
the integer converted to a string.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(long value)
Converts the specified long to its string representation.

参数:
value - the long.
返回:
the long converted to a string.
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(Object value)
Converts the specified object to its string representation. If the object is null return the string  "null", otherwise use  toString() to get the string representation.

参数:
value - the object.
返回:
the object converted to a string, or the string  "null".
从以下版本开始:
Android 1.0

valueOf

public static String valueOf(boolean value)
Converts the specified boolean to its string representation. When the boolean is  true return  "true", otherwise return  "false".

参数:
value - the boolean.
返回:
the boolean converted to a string.
从以下版本开始:
Android 1.0

contentEquals

public boolean contentEquals(StringBuffer strbuf)
Returns whether the characters in the StringBuffer  strbuf are the same as those in this string.

参数:
strbuf - the StringBuffer to compare this string to.
返回:
true if the characters in  strbuf are identical to those in this string. If they are not,  false will be returned.
从以下版本开始:
Android 1.0

contentEquals

public boolean contentEquals(CharSequence cs)
Compares a  CharSequence to this  String to determine if their contents are equal.

参数:
cs - the character sequence to compare to.
返回:
true if equal, otherwise  false
从以下版本开始:
Android 1.0

matches

public boolean matches(String expr)
Determines whether this string matches a given regular expression.

参数:
expr - the regular expression to be matched.
返回:
true if the expression matches, otherwise  false.
抛出:
PatternSyntaxException - if the syntax of the supplied regular expression is not valid.
从以下版本开始:
Android 1.0

replaceAll

public String replaceAll(String expr,
                         String substitute)
Replace any substrings within this string that match the supplied regular expression  expr, with the string  substitute.

参数:
expr - the regular expression to match.
substitute - the string to replace the matching substring with.
返回:
the new string.
抛出:
PatternSyntaxException - if the syntax of the supplied regular expression is not valid.
从以下版本开始:
Android 1.0
另请参见:
Pattern

replaceFirst

public String replaceFirst(String expr,
                           String substitute)
Replace the first substring within this string that matches the supplied regular expression  expr, with the string  substitute.

参数:
expr - the regular expression to match.
substitute - the string to replace the matching substring with.
返回:
the new string.
抛出:
PatternSyntaxException - if the syntax of the supplied regular expression is not valid.
从以下版本开始:
Android 1.0
另请参见:
Pattern

split

public String[] split(String expr)
Splits this string using the supplied regular expression  expr.

参数:
expr - the regular expression used to divide the string.
返回:
an array of Strings created by separating the string along matches of the regular expression.
抛出:
PatternSyntaxException - if the syntax of the supplied regular expression is not valid.
从以下版本开始:
Android 1.0
另请参见:
Pattern

split

public String[] split(String expr,
                      int max)
Splits this string using the supplied regular expression  expr. The parameter  max controls the behavior how many times the pattern is applied to the string.

参数:
expr - the regular expression used to divide the string.
max - the number of entries in the resulting array.
返回:
an array of Strings created by separating the string along matches of the regular expression.
抛出:
PatternSyntaxException - if the syntax of the supplied regular expression is not valid.
从以下版本开始:
Android 1.0
另请参见:
Pattern.split(CharSequence, int)

subSequence

public CharSequence subSequence(int start,
                                int end)
Has the same result as the substring function, but is present so that string may implement the CharSequence interface.

指定者:
接口  CharSequence 中的  subSequence
参数:
start - the offset the first character.
end - the offset of one past the last character to include.
返回:
the subsequence requested.
抛出:
IndexOutOfBoundsException - if  start < 0end < 0start > end or  end > length().
从以下版本开始:
Android 1.0
另请参见:
CharSequence.subSequence(int, int)

codePointAt

public int codePointAt(int index)
Retrieves the Unicode code point (character) value at the specified  index.

参数:
index - the index to the  char code unit within this string.
返回:
the Unicode code point value.
抛出:
IndexOutOfBoundsException - if  index is negative or greater than or equal to  length().
从以下版本开始:
Android 1.0
另请参见:
Character.codePointAt(char[], int, int)

codePointBefore

public int codePointBefore(int index)
Retrieves the Unicode code point value that precedes the specified  index.

参数:
index - the index to the  char code unit within this string.
返回:
the Unicode code point value.
抛出:
IndexOutOfBoundsException - if  index is less than 1 or greater than  length().
从以下版本开始:
Android 1.0
另请参见:
Character.codePointBefore(char[], int, int)

codePointCount

public int codePointCount(int beginIndex,
                          int endIndex)
Calculates the number of Unicode code points between  beginIndex and  endIndex.

参数:
beginIndex - the inclusive beginning index of the subsequence.
endIndex - the exclusive end index of the subsequence.
返回:
the number of Unicode code points in the subsequence.
抛出:
IndexOutOfBoundsException - if  beginIndex is negative or greater than  endIndex or  endIndex is greater than  length().
从以下版本开始:
Android 1.0
另请参见:
Character.codePointCount(CharSequence, int, int)

contains

public boolean contains(CharSequence cs)
Determines if this  String contains the sequence of characters in the  CharSequence passed.

参数:
cs - the character sequence to search for.
返回:
true if the sequence of characters are contained in this string, otherwise  false.
从以下版本开始:
Android 1.0

offsetByCodePoints

public int offsetByCodePoints(int index,
                              int codePointOffset)
Returns the index within this object that is offset from  index by  codePointOffset code points.

参数:
index - the index within this object to calculate the offset from.
codePointOffset - the number of code points to count.
返回:
the index within this object that is the offset.
抛出:
IndexOutOfBoundsException - if  index is negative or greater than  length() or if there aren't enough code points before or after  index to match  codePointOffset.
从以下版本开始:
Android 1.0

format

public static String format(String format,
                            Object... args)
Returns a formatted string, using the supplied format and arguments, using the default locale.

参数:
format - a format string.
args - arguments to replace format specifiers (may be none).
返回:
the formatted string.
抛出:
IllegalFormatException - if the format is invalid.
从以下版本开始:
Android 1.0
另请参见:
Formatter

format

public static String format(Locale loc,
                            String format,
                            Object... args)
Returns a formatted string, using the supplied format and arguments,accordingly to the specified locale.

Note that this is a convenience method. Using it involves creating aninternal Formatter instance on-the-fly, which issomewhat costly in terms of memory and time. This is probably acceptableif you use the method only rarely, but if you rely on it for formatting alarge number of strings, consider creating and reusing your ownFormatter instance instead.

参数:
loc - the locale to apply;  null value means no localization.
format - a format string.
args - arguments to replace format specifiers (may be none).
返回:
the formatted string.
抛出:
IllegalFormatException - if the format is invalid.
从以下版本开始:
Android 1.0
另请参见:
Formatter
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值