字符串相关类
创建String对象
- 直接赋值字符串字面量
String str = "Hello World!";
- 根据字节数组创建String对象(默认UTF-8)
String str = String(byte[] bytes);
String str = String(byte[] bytes, int offset, int count);
String常用方法
- String.charAt(int index) 获取字符串中索引值为index的字符
String str = "hello,world";
char c = str.charAt(0);
- String.compareTo(String anotherString) 比较字符串的大小
int num = "hello".compareTo("hehe");
String.compareToIgnoreCase(String str)
- 其他常用方法
String concat(String str);
boolean contains(CharSequence s);
boolean endsWith(String suffix);
boolean startsWith(String prefix);
boolean equals(Object anObject);
boolean equalsIgnoreCase(String anotherString);
byte[] getBytes();
byte[] getBytes(String charsetName);
int indexOf(String str);
int lastIndexOf(String str);
String substring(int beginIndex);
String substring(int beginIndex, int endIndex);
String[] split(String regex);
String replace(CharSequence target, CharSequence replacement);
char[] toCharArray();
String toLowerCase();
String toUpperCase();
String trim();
static String valueOf(int i);
static String valueOf(Object obj);