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

    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]);
            }
        }
    
    }
  • 相关阅读:
    JQuery学习
    前端Web APIs 二
    前端Web APIS
    Swift 函数式数据结构
    JAVA 四大域对象总结
    Java 访问 C++ 方法:JavaCPP
    写Java也得了解CPU–CPU缓存
    Servlet使用注解标注监听器(Listener)
    Java使用Fork/Join框架来并行执行任务
    Linux学习之让进程在后台可靠运行的方法详解
  • 原文地址:https://www.cnblogs.com/liaoliao/p/5052921.html
Copyright © 2011-2022 走看看