美文网首页
Java 基础Api

Java 基础Api

作者: 1baibai | 来源:发表于2021-11-08 14:35 被阅读0次

    1. 字符串


            String s = "this is java   ";
            String t = "this is Java";
    
            /* 转大写  */
            System.out.println(s.toUpperCase(Locale.ROOT));
            /*小写*/
            System.out.println(s.toLowerCase(Locale.ROOT));
            /*相等*/
            System.out.println(s.equals(t));
            /*忽略大小写*/
            System.out.println(s.equalsIgnoreCase(t));
            /*字符包含*/
            System.out.println(s.contains("is"));
            /*字符截取*/
            System.out.println(s.substring(5,7));
            /*字符去除空格*/
            System.out.println(s.trim());
            /*字符去除空格*/
            //System.out.println(s.strip());
            /*空字符*/
            System.out.println(s.isEmpty());
            /*空字符*/
            //System.out.println(s.isBlank());
            /*字符替换*/
            System.out.println(s.replace('h','A'));
            /*正则替换指点字符*/
            System.out.println(s.replaceAll("[i]+", "vv"));
    
    
            /*分割字符串 -> 字符数组*/
            System.out.println(s.split("\\\n"));
            /*字符数组 -> 字符串*/
            System.out.println(String.join("",new String[]{"J", "a", "v", "a"}));
            /*格式化*/
            System.out.println(String.format("my name is %s, age is %d, i have %.2f kg", "Jonbse", 65, 45.8));
            /*数字 -> 字符串*/
            System.out.println(String.valueOf(10086));
            /*浮点数 -> 字符串*/
            System.out.println(String.valueOf(34.55));
            /*bool -> 字符串*/
            System.out.println(String.valueOf(true));
            /*整数 -> 字符串*/
            System.out.println(Integer.parseInt("10086"));
            /*字符 -> 16进制*/
            System.out.println(Integer.parseInt("ff", 16));
            /*bool -> 字符串*/
            System.out.println(Boolean.parseBoolean("FALSE"));
            /*String对应的系统变量 -> Integer*/
            System.out.println(Integer.getInteger("java.version"));
            /*字符串 -> 字符数组*/
            System.out.println("Java".toCharArray().length);
            /*字符数组 -> 字符串*/
            System.out.println(new String("Java".toCharArray()));
            /*字符串 -> byte[]*/
            System.out.println(s.getBytes(StandardCharsets.UTF_8));
            /*byte[] - 字符串*/
            System.out.println(new String(s.getBytes("GBK"),"GBK"));
    
            /*可变字符串*/
            StringBuilder stringBuilder = new StringBuilder(1024);
            stringBuilder.append('h').append('e').append('l').insert(stringBuilder.length(), "low");
            System.out.println(stringBuilder.toString());
    

    相关文章

      网友评论

          本文标题:Java 基础Api

          本文链接:https://www.haomeiwen.com/subject/lcpgaltx.html