String类题目methods总结

mac2022-06-30  83

用到的Class和methods:

1. 类String

(1)charAt

String s;

s.charAt(i);

 

(2)split

分割一个String用split:

public String[] split(String regex) RegexResult:{ "boo", "and", "foo" }o{ "b", "", ":and:f" }

 

(3) trim删除空格

public String trim() Returns a copy of the string, with leading and trailing whitespace omitted.     (4)equals public boolean equals(Object anObject) Compares this string to the specified object. The result is  true if and only if the argument is not  null and is a  String object that represents the same sequence of characters as this object. example: http://www.cnblogs.com/hygeia/p/4830911.html  

 

2. 类Character: http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html

用法类似Character.isLetterOrDigit(s.charAt(i))

(1) isLetterOrDigit(char ch)

Determines if the specified character is a letter or digit. Return static boolean example: http://www.cnblogs.com/hygeia/p/4830949.html   (2) toLowerCase(char ch) Converts the character argument to lowercase using case mapping information from the UnicodeData file. Return static char   (3) isWhitespace ( char ch) Determines if the specified character is white space according to Java.   (4)i s Digit( char ch) Determines if the specified character is a digit.     3. 类 StringBuilder:http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html   (1) append(char c) Appends the string representation of the  char argument to this sequence. return  StringBuilder   (2)toString() Returns a string representing the data in this sequence. return  String   4. 转化 (1) Integer to String String.valueOf(number) (my preference)"" + number (I don't know how the compiler handles it, perhaps it is as efficient as the above)Integer.toString(number) (2) String to Integer   Integer x = Integer.valueOf(str);   // or   int y = Integer.parseInt(str);

 

 

转载于:https://www.cnblogs.com/hygeia/p/4793476.html

最新回复(0)