java string类型数据 输出方法应用总结

string类型表示输出输入字符串。

String a=" sfa asdf453";
String b=“ss”;
String c=“ss”;
System.out.println(a);

	System.out.println("lastIndexOf 返回字符串的下标值,从末尾开始查找");
	System.out.println(a.lastIndexOf("s"));
	System.out.println("indexOf 返回字符串的下标值,从头开始查找");
	System.out.println(a.indexOf("4"));
	System.out.println(a.indexOf("s"));
	System.out.println(a.indexOf("sdf4"));
	System.out.println("indexOf 如果字符串不存在,就返回 -1");
	System.out.println(a.indexOf("aa"));
	System.out.println("contains 包含了,就是真");
	System.out.println(a.contains("f"));
	System.out.println("charAt 返回下标对应的字符");
	System.out.println(a.charAt(1));
	System.out.println(a.charAt(11));

// System.out.println(a.charAt(12));
System.out.println(“判断两个字符串是不是相同,用equals方法”);
//判断两个字符串是不是相同,用equals方法
System.out.println(a.equals(b));
System.out.println(c.equals(b));
System.out.println(“判断结尾的值”);
//判断结尾的值
System.out.println(a.endsWith(“3”));
System.out.println(a.endsWith(“53”));
System.out.println(a.endsWith(“153”));
//消除前后的空格
System.out.println(“消除前后的空格”);
System.out.println(a.trim());
System.out.println(“截取字符串”);
System.out.println(a.substring(0, 3));
System.out.println(a.substring(a.length()-3, a.length()-1));
System.out.println(“字符串的长度”);
System.out.println(a.length());
String[] x = new String[a.length()];

}

你可能感兴趣的:(java string类型数据 输出方法应用总结)