String 常用Api
作者:互联网
package com.itheima; public class string { public static void main(String[] args) { String s1 = "qwertyuio"; String s3 = "QWErtyuio"; System.out.println(s1.equals(s3)); //进行比较,不区分大小写 System.out.println(s1.equalsIgnoreCase(s3)); //长度 System.out.println(s1.length()); //索引字符 System.out.println(s1.charAt(1)); //打印字符串 for (int i = 0; i < s1.length(); i++) { System.out.print(s1.charAt(i)); } //将字符串转换为字符数组 char[] chars = s1.toCharArray(); //字符串子串 System.out.println(s1.substring(4)); System.out.println(s1.substring(1, 5)); //替换字符串,String不可变性 String replace = s1.replace("q", "e"); System.out.println(replace); System.out.println(s1); //包含,返回bool System.out.println(s1.contains("qwe")); //判断字符串是否以指定字符串开头 System.out.println(s1.startsWith("qwer")); String s4 = "a,b,c,d"; String[] s5 =s4.split(","); for (int i = 0; i < s5.length; i++) { System.out.print(s5[i]+"\t"); } } }
标签:常用,String,s1,System,字符串,Api,println,out 来源: https://www.cnblogs.com/sen5463/p/16615396.html