java---String工具类方法使用

package cn.tedu.api;

import java.util.Arrays;

public class Test3_String {
    public static void main(String[] args) {
        char[] c = new char[]{'a', 'b', 'c', 'd', 'e'};
        String s = new String(c);
        String s1 = s + 'F';
        String s2 = ' ' + s + 'F' + ' ';
        System.out.println(s);
        System.out.println(s.charAt(3));//返回指定索引的字符
        System.out.println(s.concat("fgh"));//在s后拼接fgh字符串不保存输出,拼接后s仍为abcde
        System.out.println(s);//abcde
        System.out.println(s.contains("bc"));//包含bc则输出true
        System.out.println(s.endsWith("de"));//判断是否以de结束
        System.out.println(s.equals("abcde"));//判断是否相等
        System.out.println(s.hashCode());//输出哈希码
        System.out.println(s.indexOf("c"));//返回指定子字符串在此字符串中第一次出现处的索引。
        System.out.println(s.indexOf("bcd"));
        System.out.println(s.indexOf("bcf"));//不存在返回 -1
        System.out.println(s.isEmpty());//判断是否为空
        System.out.println(s.length());//字符串长度
        System.out.println(c.length);//数组长度
        System.out.println(s.lastIndexOf("de"));//返回指定子字符串在此字符串中第一次出现处的索引。---3
        System.out.println(s.lastIndexOf('e'));//返回指定字符在此字符串中第一次出现处的索引。
        System.out.println(s.lastIndexOf('e', 2));//返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。
        System.out.println(s.startsWith("ab"));//测试此字符串是否以指定的前缀开始
        System.out.println(s1.toLowerCase());//使用默认语言环境的规则将此 String 中的所有字符都转换为小写
        System.out.println(s1.toUpperCase());//使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
        System.out.println(s1.substring(1));//返回一个新的字符串,它是此字符串的一个子字符串。从下标1开始
        System.out.println(s1.substring(0, 4));//返回一个新的字符串,它是此字符串的一个子字符串。从下标1到下标(4-1)=3,---bcd
        System.out.println(s2);
        System.out.println(s2.trim());// 返回字符串的副本,忽略前导空白和尾部空白
        char[] s0 = s2.toCharArray();
        System.out.println(Arrays.toString(s0));
        System.out.println(s0.length);//前后多了空格长度为8
        System.out.println(s0[0]);//将此字符串转换为一个新的字符数组。空格
        System.out.println(s0[1]);//将此字符串转换为一个新的字符数组。a
        System.out.println(s0[6]);//将此字符串转换为一个新的字符数组。F
        System.out.println(s0[7]);//将此字符串转换为一个新的字符数组。空格
        String str = String.valueOf(10.2);//把10转换成String类型
        System.out.println(str + 1);//10.21
        byte[] b = s.getBytes();//String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。
        System.out.println(Arrays.toString(b));
        String s5 = "ab1cd1ef1xy1ddsa1gd1rb1";
        String[] s4 = s5.split("1");//根据给定正则表达式的匹配拆分此字符串
        System.out.println(Arrays.toString(s4));//[ab, cd, ef, xy, ddsa, gd, rb]

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值