package com.Tree.javase.String;
// 关于String类中常用的方法
// 1 char charAt(int index) // 返回指定索引处的char值
// 2 int compareTo(String anotherString) // 按字典顺序比较两个字符串
// 3 boolean contains(CharSequence s) // 判断当前的字符串中是否包含后面的子字符串
// 4 boolean endsWith(String suffix) // 判断当前字符串是否以某个字符串结尾
// 5 boolean equals(Object anObject)
// 6 boolean equalsIgnoreCase(String anotherString) // 在忽略大小写的情况下,判断两个字符串是否相等
// 7 byte[] getBytes() // 将字符串对象转换成字节数组
// 8 int indexOf(String str) // 判断某个子字符串在当前字符串中第一次出现处的索引(下标)
// 9 boolean isEmpty() // 判断某个字符串是否为空,空格不是空字符串
// 10 int length() // 判断字符串长度,判断数组长度是length属性,判断字符串长度是length()方法
// 11 int lastIndexOf(String str) // 判断某个字符串在当前字符串中最后一次出现的索引(下标)
// 12 String replace(CharSequence target,CharSequence replacement) // 字符串替换
// 13 String[] split(String regex) // 拆分字符串
// 14 boolean startsWith(String prefix) // 判断当前字符串是否以某个字符串开始
// 15 String substring(int beginIndex) // 从当前字符串的某个位置开始截取字符串
// 16 String substring(int beginIndex,int endIndex) // 左闭右开截取字符串
// 17 char[] toCharArray() // 将一个字符串转换成char数组
// 18 String toLowerCase() // 将所给字符串全部转换为小写
// 19 String toUpperCase() // 将所给字符串全部转换为大写
// 20 String trim() // 去除字符串前后空白,中间的空白不能去掉
// 21 valueOf() // String中唯一的静态方法,通过类名String.调用,作用是将"非字符串"转换成"字符串"
public class StringTest05 {
public static void main(String[] args) {
System.out.println("1-----------");
char c="浙江省".charAt(1);
System.out.println(c); // 江
System.out.println("2-----------");
int result1="abc".compareTo("abc");
System.out.println(result1); // 0
int result2="abc".compareTo("xyz");
System.out.println(result2); // -23 // 前小后大,按照字典顺序
System.out.println("3-----------");
System.out.println("HelloWorld.java".contains("java")); // true // 判断当前的字符串中是否包含后面的子字符串
System.out.println("http://www.baidu.com".contains("wwww.baidu")); // false
System.out.println("4-----------");
System.out.println("Test.java".endsWith("java")); // true
System.out.println("Test.java".endsWith("abcd")); // false
System.out.println("5-----------");
System.out.println("abc".equals("abc")); // true
System.out.println("6-----------");
System.out.println("AbC".equalsIgnoreCase("ABC")); // true
System.out.println("7-----------");
byte[]bytes="abcdefgh".getBytes();
for (int i=0;i