八门神器java版本_【修改教程】java基础知识字符串处理_八门神器

【Java基础知识】字符串处理1.获取字符串的长度 String s = "AIDE"; System.out.println(s "长度为:" s.length()); //主体:length() 2.转换字符的大小写 String s = "Hello World"; System.out.println(s.toLowerCase()); System.out.println(s.toUpperCase()); //主体:toLowerCase() 小写 //主体:toUpperCase() 大写 3.去除字符中的首尾空格 String s = " Hello World "; System.out.println(s.trim()); //主体:trim() 4.在字符串中找到指定字符的位置 String s = " Hello World "; System.out.println(s.indexOf("W")); //主体:indexOf(string i) 5.比较两个字符,相同得true,不同的false String s = "AIDE"; System.out.println(s.equals("aide")); System.out.println(s.equalsIgnoreCase("aide")); //主体:equals(string i) 区分大小写 //主体:equalsIgnoreCase(string s) 不区分大小写 6.获取字符串中指定位置的字符 String s = "AIDE"; System.out.println(s.charAt(2)); //主体:charAt(int i) 7.获取指定字符串内容进行替换 String s = "Hello Java"; System.out.println(s.replace("Java","World")); //主体:replace(string s,string s) 8.指定起始位与结束位截取字符 String s = "I like Java"; System.out.println(s.substring(2,6)); //主体:substring(int i,int i) 9.将两个单独的字符进行合并 String s = "I like "; System.out.println(s.concat("Java")); //主体:concat(string s) 10.判断字符串中是否包含某个字符,包含为true,不包含为false String s = "Hello World"; System.out.println(s.contains("Hello")); //主体:boolean contains(string s); 11.判断字符串中是否为空,为空true,不为空false String s = ""; System.out.println(s.isEmpty()); //主体:isEmpty(); 12.判断字符串是否以指定内容开头,是为true,不是为false String s = "

http://www.baidu.com"; System.out.println(s.startsWith("http://")); //主体:startsWith(string s) 13.判断字符串是否以指定内容结尾,是为true,不是为false String s = "

http://www.baidu.com"; System.out.println(s.endsWith(".com")); //主体:endsWith(string s); 14.字符串类型转换为布尔类型 boolean bl = Boolean.getBoolean("false"); System.out.println(bl); //主体:Boolean.getBoolean(string s); 15.字符串类型转换为整型 int i = Integer.parseInt("20"); System.out.println(i); //主体:Integer.parseInt(string s); 16.字符串类型转换为长整型 long l = Long.parseLong("1024"); System.out.println(l); //主体:Long.parseLong(string s); 16.字符串类型转换为单精度浮点型 float f = Float.parseFloat("1.521"); System.out.println(f); //主体:Float.parseFloat(string s); 17.字符串类型转换为双精度浮点型 double d = Double.parseDouble("1.52123"); System.out.println(d); //主体:Double.parseDouble(string s); 18.字符串类型转换为byte型 byte bt = Byte.parseByte("200"); System.out.println(bt); //主体:Byte.parseByte(string s); 19.将布尔类型转换为字符串类型 String strb1 = String.valueOf(bool); System.out.println(strb1); //主体:valueOf(bool); 20.将整形转换为字符串类型 String stri1 = String.valueOf(int); System.out.println(stri1); //主体:valueOf(integer); 21.将长整型转换为字符串类型 String strl1 = String.valueOf(long); System.out.println(strl1); //主体:valueOf(long); 22.将单精度浮点型转换为字符串类型 String strf1 = String.valueOf(float); System.out.println(strf1); /#主体:valueOf(float); 23.将double类型转换为字符串类型 String strd1 = String.valueOf(double); System.out.println(strd1); //主体:value(double); 24.将byte转换为字符串类型 String strbt1 = String.valueOf(byte); System.out.println(strbt1); //主体:value(byte) 25.将字符型转换为字符串类型 String strch1 = String.valueOf(ch); System.out.println(strch1); //主体:value(char) 26.将浮点数进行舍入 float f = 3.5415F; System.out.println(Math.round(f)); //主体:Math.round(int i) 27.整数转二进制 String b = Integer.toBinaryString(100); System.out.println(b); //主体:toBinaryString(int i) 28.整数转八进制 String b = Integer.toOctalString(100); System.out.println(b); //主体:toOctalString(int i) 29.整数转十六进制 String b = Integer.toHexString(100); System.out.println(b); //主体:toHexString(int i) 30.字符串反转 String b = new StringBuffer("Hello").reverse().toString(); System.out.println(b); //主体:reverse() 31.生成随机数字 int i=(int)(10*Math.random()); System.out.println(i); //主体:Math.random()

b556dccbae96cbc16c13e98f23843012.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值