package com.fei.test;
public class Test {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "helloworld";
String s3 = "HELLOworld";
//一、判断功能的方法
//equals()方法:判断两个字符串的值是否相等|| 源码:public boolean equals(Object object)
System.out.println(s1.equals(s2));//true
//equalsIgnoreCase():忽略大大小写,比较字符串是否相等||源码:public boolean equalsIgnoreCase(String str)
System.out.println(s1.equals(s3));//false
System.out.println(s1.equalsIgnoreCase(s3));//true
//二、获得功能的方法
//length():返回字符串长度||源码:public int length()
System.out.println(s1.length());//10
//concat(String str):将字符串拼接到字符串对象的末尾||源码:public String concat(String str)
System.out.println(s1.concat(s3));//helloworldHELLOworld
//charAt(int index):返回指定索引处的字符||源码:public char charAt(int index)
System.out.println(s1.charAt(2));//l
//indexof(String str):返回字符串第一次出现在该字符串的索引||源码:public int indexOf(String str)
System.out.println(s1.indexOf("llo"));//2
//substring(int beginIndex):截取beginIndex以及后面的字符串 public String substring(int beginIndex)
System.out.println(s1.substring(5));//world
//subString(int beginIndex,int endindex):截取[beginindex,endindex)之间的字符串||源码:public String sunstring(beginindex,int endindex)
System.out.println(s1.substring(0,5));
//三、转换功能的方法
//toCharArray():字符串改成字符数组||源码:public char[] toCharArray()
char[] arry = s1.toCharArray();
for(char e:arry)
System.out.print(e+" ");//h e l l o w o r l d
//getBytes():返回字节型数组||源码: public byte[] getBytes()
byte[] arry2 = s1.getBytes();
for(int e:arry2)
System.out.print(e+" ");//104 101 108 108 111 119 111 114 108 100
//四、分割功能的方法
//split(String regex):返回字符串数组,字符串按照regex切割||源码:public String[] split(regex)
String s4 = "aa,bb,cc";
String[] arry3 = s4.split(",");
for(String e:arry3)
System.out.print(e+" ");//aa bb cc
}
}