package com.sxt;
import java.util.Arrays;
public class StringDemo01 {
public static void main(String[] args) {
String s=" a#cc#de#f"; //定义一个字符串
char ss[]=s.toCharArray(); //转成字符数组
byte s2[]=s.getBytes(); //转成字节数组
String s3=s.trim(); //去除首尾空格
String[]s4=s.split("#"); //用“#”做分隔符分割成字符串数组
boolean bl=s.contains("de"); //判断是否包含
boolean bl1=s.equalsIgnoreCase(" A#cc#de#F"); //忽略大小写判断是否相等
boolean bl2=s3.startsWith("a"); //是否以指定字母开头
boolean bl3=s3.endsWith("a"); //是否以指定字母结尾
int i=s.indexOf("a"); //返回指定字符串的下标,没有则返回-1
int j=s3.indexOf("a", 2); //从指定下标开始返回第一个字符串的下标
char a = s3.charAt(6); //返回字符串中下标是6的字符
String s6=String.valueOf(ss); //基本数据类型转换为String类型
String s5=s3.substring(1, 2); //返回一个切割后的子串,包头不包尾
String s7=s3.replace("a","3"); //用3替换a
String s8=s3.toUpperCase(); //转换成大写
String s9=s3.toLowerCase(); //转换成小写
int k=s3.compareTo(s); //比较自然顺序
System.out.println(Arrays.toString(s2));
System.out.println(s3);
System.out.println(Arrays.toString(s4));
System.out.println(Arrays.toString(ss));
System.out.println(bl);
System.out.println(bl1);
System.out.println(i);
System.out.println(s5);
System.out.println(a);
System.out.println(bl2+""+bl3);
System.out.println(j);
System.out.println(s6);
System.out.println(s7);
System.out.println(s8);
System.out.println(s9);
System.out.println(k);
Syetem.out.println(String.join("#","A","B"))
}
}
java中String类的方法总结
最新推荐文章于 2022-11-02 10:25:52 发布