java String类型的处理

今天在看String的处理,就把基本操作联系了下,顺便写下。

//练习用的main方法
public static void main(String[] args) {
    //世界,你好。
    //System.out.println("hello world~~");

    //类型转化的时候,有三种可能会有精度损失的转换
    //① int 转 float     float的长度大小为-3.4E38~3.4E38之间,而int比这个大。
    int n = 123456789;
    float f = n;
//        System.out.println(f);   //f = 1.23456792E8
//        http://blog.csdn.net/m1n_love/article/details/55224990   参考链接
//② long 转 int     原因同上 
//③ long 转 float   原因同上

//判断是否相等。 equals  判断是否相等 equalsIgnoreCase 不区分大小写
//        String s = "hehe";
//        String s1 = "heHe";
//        if(s.equalsIgnoreCase(s1)){
//            System.out.println("==");
//        }else{
//            System.out.println("!=");
//        }
//判断字符串中是否包含某个词      indexOf()   不包含返回 -1,包含返回在字符串中第一次出现的下标   lastIndexOf   包含返回在字符串中最后一次出现的下标
//        String s = "suixin";
//        System.out.println(s.indexOf("ui"));
//        System.out.println(s.lastIndexOf("i"));
        //检查是否存在
//        String s1 = "user.text";
//        if(s1.contains(".")){
//            System.out.println("1");
//        }else{
//            System.out.println("2");
//        }
//判断字符串自否包含某个字符   返回true或者false
//        String s = "koreyoshi";
//        Boolean res = s.contains("ke");
//        System.out.println(res);
//字符串替换
//        String s = "koreyoshi";
//        String s1 = s.replace("kor","yyy");
//        System.out.println(s1);
//测试是否以指定字符串开始
//        String s = "koreyoshi";
//        Boolean res = s.startsWith("kor");
//        System.out.println(res);
//字符串截取             默认截取,从beginIndex到船尾或者是endIndex的所有代码的单位。如果endIndex>字符串的总长度 会报错。
//          String s = "koreyoshi";
//          String s1 = s.substring(1);
//          System.out.println(s1);
//字符串大小写转换   toLowerCase  变成小写  toUpperCase  变成大写
//        String s = "KOREYOHSI";
//        String S1 = s.toLowerCase();
//        System.out.println(S1);
//去除空格  trim
        String s = " koreyoshi   ";
        System.out.println(s);
        String s1 = s.trim();
        System.out.println(s1);
//分割字符串            特殊情况,另一篇博客有写
//        String s2 = "user\\text";
//        String[] fieldPath = s2.split("\\\\");
//        for (int i = 0; i < fieldPath.length; i++) {
//            System.out.println(fieldPath[i]);
//        }
//        System.out.println(fieldPath[0]);

//        String s2 = "acount=? and num =? or u=?";
//        String[] fieldPath = s2.split("and|or");
//        for (int i = 0; i < fieldPath.length; i++) {
//            System.out.println(fieldPath[i]);
//        }
//        System.out.println(fieldPath[2]);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值