zoukankan      html  css  js  c++  java
  • java.lang.String的常用方法

    /*
             * 按照面向对象的思想对字符串进行功能分类。
             * "abcd"
             * 
             * 1,获取:
             * 1.1 获取字符串中字符的个数(长度).
             *         int length();
             * 1.2 根据位置获取字符。
             *         char charAt(int index);
             * 1.3 根据字符获取在字符串中的第一次出现的位置.
             *         int indexOf(int ch)
             *         int indexOf(int ch,int fromIndex):从指定位置进行ch的查找第一次出现位置 
             *         int indexOf(String str);
             *         int indexOf(String str,int fromIndex);
             *         根据字符串获取在字符串中的最后一次出现的位置.
             *         int lastIndexOf(int ch);  //反向索引一个字符出现的位置
             *         int lastIndexOf(String str);
             * 1.4 获取字符串中一部分字符串。也叫子串.
             *         String substring(int beginIndex, int endIndex)//包含begin 不包含end 。
             *         String substring(int beginIndex);
             *         
             * 
             * 
             * 2,转换。
             *         2.1 将字符串变成字符串数组(字符串的切割)
             *             String[]  split(String regex); //当分割符是 . 或 | 时,必须使用 \ 进行转义,变为"\l"或"\."。
             *         2.2 将字符串变成字符数组。
             *             char[] toCharArray();
             *         2.3 将字符串变成字节数组。
             *             byte[] getBytes();
             *         2.4 将字符串中的字母转成大小写。
             *             String toUpperCase():大写
             *             String toLowerCase():小写
             *        2.5  将字符串中的内容进行替换
             *            String replace(char oldch,char newch);
             *             String replace(String s1,String s2);
             *         2.6 将字符串两端的空格去除。
             *             String trim();
             *         2.7 将字符串进行连接 。
             *             String concat(String);
             *        2.8 将字符数组转换成字符串。
             *            构造函数:String(char[])
             *                     String(char[],offset,count):将字符数组中的一部分转换成字符串。
             *            静态方法:
             *                     static String copyValueOf(char[]);
             *                     static String copyvalueOf(char[] data, int offset, int count); //static String valueof(Object object);        
             *        2.9 将字节数组转换成字符串。
             *                     String(byte[])
             *                     String(byte[],offset,count):将字节数组中的一部分转换成字符串。
             * 3,判断
             *         3.1 两个字符串内容是否相同
             *             boolean equals(Object obj);
             *             boolean equalsIgnoreCase(String str);//忽略大写比较字符串内容。
             *         3.2 字符串中是否包含指定字符串
             *             boolean contains(String str);
             *         3.3 字符串是否以指定字符串开头。是否以指定字符串结尾。
             *             boolean startsWith(String);
             *             boolean endsWith(String);
             *        2.4 字符中是否有内容。
                        boolean isEmpty(); //原理就是判断长度是否为0.
             *         
             * 4,字符串大小比较
             *      4.1 字符串大小比较
             *             int compareTo(String anotherString);
             *            int compareToIgnoreCase(String anotherString);
             *     //输出三种比较结果:unicode值>,返回正数。=返回0,<返回负数。
             
             */    
  • 相关阅读:
    Investment
    The Fewest Coins
    Bone Collector II
    Cow Exhibition
    饭卡
    A + B Problem II
    F
    敌兵布阵
    单例模式
    面向对象
  • 原文地址:https://www.cnblogs.com/shijianchuzhenzhi/p/13056117.html
Copyright © 2011-2022 走看看