• 151010


    //字符串
            
            String str = "aa";
            
            char c = 'd';
            
            int j = 1000;
            
            String st = new String("abc");
            
            char[] cc = {'a','b'};
            
            String str2 = new String(cc);
            
            System.out.println("str2 = " + str2);
            
            //连接字符串 +
            
            System.out.println("st + str2 + j = " + st  + str2 + j);
            
            // 99乘法表
            
            int [] a = new int[5];
            
            int l = a.length;//是属性
            
            int g = st.length();//是方法
            
            System.out.println("st.length() = "+ g);
            
            //查找
            
            int sy = st.indexOf("");
            
            System.out.println("st.indexOf("") = " + sy);
            
            int sy1 = st.lastIndexOf("bc");
            
            System.out.println("st.LastIndexOf("") = " + sy1);
            
            //取出字符
            
            System.out.println("charAt = " + st.charAt(2));
            
            //截取字符串
            
            System.out.println("substringf = " + st.charAt(1));
            
            //字符串 去除空格
            
            String str3 = "  abc def gh  ";
            
            System.out.println("str3.trim() =#" + str3.trim() + "#");
            
            str3 = str3.trim();
            
            System.out.println("str3 =#" + str3 + "#");
            
            //替换
            
            str3 = str3.replace("", "");
            
            System.out.println("str3.replace() =#" + str3 +"#");
            
            str3 = str3.replace("bc", "kk");
            
            System.out.println("str3.replace() =#" + str3 +"#");
            
            //判断字符串开始和结尾
            
            System.out.println("str3.startsWith() = " + str3.startsWith("ab"));
            
            String a1 = new String("aaa");
            
            String a2 = new String("aAa");
            
            System.out.println("a1 == a2 = " + a1 == a2);//比较的是内存地址
            
            System.out.println("a1.equals(a2) = " +a1.equals(a2));
            
            System.out.println("a1.equalsIgnoreCase(a2) = " +a1.equalsIgnoreCase(a2));
            
            //按字典顺序比较 Unicode的值
            
            System.out.println("compareTo = " + a1.compareTo(a2));
            
            //大小写转换
            
            System.out.println("a1.toUpperCase = " + a1.toUpperCase());
            
            a1.toLowerCase();
            
            //字符串分隔 aa;bb;cc;dd;
            
            String fg = "aa;bbb;cc,ccc;sdd5sss";
            
            String[] arr = fg.split(";");
            
            String[] arr2 = fg.split(";|5");// "."不能作为分隔符
            
            String[] arr1 = fg.split(";",3);
            
            for(String f : arr2)
            {
                System.out.println(f);
            }
            
            //格式化字符串 日期时间 静态方法
            //String.format(格式符,要被格式化的对象)
            
            Date dt = new Date();//实例化日期,生成当前日期
            
            System.out.println(String.format("%tF", dt));
            
            System.out.println(String.format("%tT", dt));
            
            System.out.println(String.format("%tF", dt) + "" + String.format("%tT", dt));
            
            System.out.println("200的十六进制 = " + String.format("%x",200));
            
            System.out.println("特定换行 " + String.format("%n") + "换行");
  • 相关阅读:
    react-echarts之折线图的显示
    Log4j2
    测试驱动开发Junit4
    JavaWeb基础: Cookie
    JavaWeb前端:Bootstrap基础
    JavaWeb前端:CSS
    JavaWeb前端:JQuery
    Android基础:Activity
    JavaWeb前端: JavaScript 简介
    JavaWeb前端:HTML5 简介
  • 原文地址:https://www.cnblogs.com/zhuxiaolin/p/4870108.html
Copyright © 2020-2023  润新知