千峰逆战班,day21

在千峰“逆战班”学习的第21天
清醒温柔知进退,努力上进且优秀
今天的学习内容是Object中的finalize()方法,以及包装类中的转型
中国加油!武汉加油!千峰加油!我自己加油

作业:

package com.qf.day20.test;

public class TestCache { 
	public static void main(String[] args) {
		String s = "HelloWorld";
		System.out.println(s.charAt(1)); //获取下标1的字符“e”
		
		//判断s中是否包含“Hello” , 有返回true,没有返回false
		System.out.println(s.contains("Hello")); 
		
		char[] chs = s.toCharArray();  //将s转换为char类型的数组
		for(int i = 0; i < chs.length ; i++){  //遍历整个数组
			System.out.print(chs[i]);
		}
		System.out.println("\n");
		System.out.println(s.indexOf("l")); //l首次出现的下标为2
		System.out.println(s.indexOf("llo")); //llo首次出现的下标为2
		System.out.println(s.indexOf("l",4)); //从下标4开始l首次出现的下标为2
		System.out.println(s.lastIndexOf("l"));// 查找l在字符串中最后出现时的下标
		System.out.println(s.length());// 就是调字符串s转换成数组后的长度
		String s1 = "     Hello   World    ";
		System.out.println(s1.trim());   //去掉字符串前后的空格
		System.out.println(s.toUpperCase());	//将字符串小写内容全部变成大写
		System.out.println(s.toLowerCase());	//将字符串大写内容全部变为小写
		System.out.println(s.endsWith("d"));	//判断字符串是否是以d结尾
		System.out.println(s.replace("el", "le"));	//将“el”替换成“le”
		String[] strs = s.split("o");	//将字符串分割,变成数组,以“o”为分割线,结果中会失去“o”
		for(int i = 0; i < strs.length; i++)
		System.out.println(strs[i]);
	} 
}  
发布了25 篇原创文章 · 获赞 0 · 访问量 911

猜你喜欢

转载自blog.csdn.net/Hydz666_/article/details/104622367
今日推荐