• 字符串用法


    package zhiZuo4;
    
    public class Test {
    
        public static void main(String[] args)
        {
            
            //声明定义字符串
            String A = "AAAAAA";
            String B = null;
            B = new String();
            B = new String("AAAAA");
            char[] c = new char[]{'A','A','A'};
            String D = new String(c);
            System.out.println("字符串D长度为"+D.length());
            System.out.println("字符串D为"+D);
            //查找字符或字符串
            int E = D.indexOf("AA");
            System.out.println(E);
            int F = D.indexOf("B");
            System.out.println(F);
            String G = "hdiasdkaenfklajksj";
            int la = G.lastIndexOf("s");
            System.out.println(la);
            //截取字符或字符串
            String H = G.substring(5);
            System.out.println(H);
            String J = G.substring(5, 6);
            System.out.println(J);
            //去除前后空格
            String K = " hu g t eyd ";
            System.out.println(K.trim());
            //查找替换
            System.out.println(K.replace(" ", ""));
            String L = "WWW,WWW,钱已经花光!";
            System.out.println(L.replaceFirst("WWW", "穷死了"));
            //判断字符串的开始和结束
            System.out.println(L.startsWith("W"));
            System.out.println((L.indexOf("W")==0));
            System.out.println(L.endsWith("!"));
            //判断字符串是否相等
            String a = new String("aBc");
            String b = new String("aBc");
            System.out.println((a==b));
            System.out.println((a.equals(b)));
            //大小写转换
            System.out.println(a.toUpperCase());
            System.out.println(b.toLowerCase());
            //字符串分割
            String a2 = "a b c d e f";
            String[] a3 = a2.split(" ");
            for (int i = 0;i<a3.length;i++)
            {
                System.out.print("	"+a3[i]);
            }
        }
    
    }
  • 相关阅读:
    ASP.NET登录记住用户名
    .NET枚举类型转为List类型
    display:inline-block 去除间隙
    sublime text 3 常用快捷键 、常用插件
    使用背景图代码
    Photo Shop 修改、维护
    前端协作流程
    Photo Shop切图
    Photo Shop 设置
    Flex 弹性布局
  • 原文地址:https://www.cnblogs.com/youshashuosha/p/5052919.html
Copyright © 2020-2023  润新知