zoukankan      html  css  js  c++  java
  • learning java 字符串常用操作

            // 字符串索引取值
            var s = "12345678";
            System.out.println(s.charAt(0));
    
            // 字符串比较
            var s1 = "1234567890";
            var s2 = "12345678";
            var s3 = "1234567870";
    
            System.out.println(s1.compareTo(s2));
            System.out.println(s1.compareTo(s3));
    
            //字符串拼接
            var s4 = "allaboutscala";
            var s5 = ".org";
    
            System.out.println(s4.concat(s5));
    
            // 字符串前缀及后缀判断
            var s6 = "www.kernel.org";
            var s7 = "www";
            var s8 = "org";
            System.out.println(s6.startsWith(s7));
            System.out.println(s6.endsWith(s8));
    
            // 字符串拷贝
            char[] s9 = {'1','2','3','4'};
            var s10 = "abc";
    
            s10.getChars(0,2,s9,0);
            System.out.println(s9);
            //字符查找
            System.out.println(s6.indexOf('w'));
            System.out.println(s6.indexOf('w',6));
    
            System.out.println(s6.lastIndexOf('w'));
    
            System.out.println(s6.replace('w','W'));
    
            System.out.println(s6.length());
    
            //字符串截取
            System.out.println(s6.substring(4));
    
            System.out.println(s6.substring(4,6));
    
            System.out.println(s6.toUpperCase());
            System.out.println(s6.toLowerCase());
    
            System.out.println(s6.toCharArray());

    output:

    1
    2
    2
    allaboutscala.org
    true
    true
    ab34
    0
    -1
    2
    WWW.kernel.org
    14
    kernel.org
    ke
    WWW.KERNEL.ORG
    www.kernel.org
    www.kernel.org
  • 相关阅读:
    C++指针
    Linux Ubuntu常用终端命令
    java-JDBC-Oracle数据库连接
    HDU 1890 区间反转
    Hdu-3487 Splay树,删除,添加,Lazy延迟标记操作
    UVa 10088
    UVa10025-The ? 1 ? 2 ? ... ? n = k problem
    UVa10023手动开大数平方算法
    UVa 10007
    点的双联通+二分图的判定(poj2942)
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/11244883.html
Copyright © 2011-2022 走看看