AJPFX总结String类的特点

      String str = "abc"; str就是String的一个对象
        字符串一旦被赋值, 值就不能再被改变了
        举例:String s = "abc"; //s被赋值为了"abc"
                     s = "bcd";        //s还能继续赋值成"bcd"
        //字符串一旦被赋值,值就不能改变,说的是 值 不能改变 ,就是说 "abc" 永远不变 永远是"abc"
        构造方法
                String s = "abc";  : s就是String的一个对象
                public String():空构造
                public String(byte[] bytes):把字节数组转成字符串
                public String(byte[] bytes,int index,int length):把字节数组的一部分转成字符串
                public String(char[] value):把字符数组转成字符串
                public String(char[] value,int index,int count):把字符数组的一部分转成字符串
                public String(String original):把字符串常量值转成字符串
        String的判断功能
                boolean equals(Object obj):比较字符串的内容是否相同,区分大小写
                boolean equalsIgnoreCase(String str):比较字符串的内容是否相同,忽略大小写
                boolean contains(String str):判断大字符串中是否包含小字符串
                boolean startsWith(String str):判断字符串是否以某个指定的字符串开头
                boolean endsWith(String str):判断字符串是否以某个指定的字符串结尾 boolean isEmpty():判断字符串是否为空。
String的获取功能
                int length():获取字符串的长度。               
                char charAt(int index):获取指定索引位置的字符
                int indexOf(int ch):返回指定字符在此字符串中第一次出现处的索引。
                int indexOf(String str):返回指定字符串在此字符串中第一次出现处的索引。
                int indexOf(int ch,int fromIndex):返回指定字符在此字符串中从指定位置后第一次出现处的索引。
                int indexOf(String str,int fromIndex):返回指定字符串在此字符串中从指定位置后第一次出现处的索引。
                int lastIndexOf(int ch):从最后往前数返回指定字符在此字符串中第一次出现处的索引。
                int lastIndexOf(String str):从最后往前数返返回指定字符串在此字符串中第一次出现处的索引。
                int lastIndexOf(int ch,int fromIndex):返回指定字符在此字符串中从指定位置往前数第一次出现处的索引。
                int lastIndexOf(String str,int fromIndex):返回指定字符串在此字符串中从指定位置往前数第一次出现处的索引。
                String substring(int start):从指定位置开始截取字符串,默认到末尾。
                String substring(int start,int end):从指定位置开始到指定位置结束截取字符串。
        String的转换功能
                byte[] getBytes():把字符串转换为字节数组。
                char[] toCharArray():把字符串转换为字符数组。
                static String valueOf(char[] chs):把字符数组转成字符串。
                static String valueOf(int i):把int类型的数据转成字符串。
                        注意:String类的valueOf方法可以把任意类型的数据转成字符串。
                String toLowerCase():把字符串转成小写
                String toUpperCase():把字符串转成大写。
                String concat(String str):把字符串拼接。
        String的其他功能
                String replace(char old,char new): 把一个字符串中的所有old字符 用new字符替换
                String replace(String old,String new):把一个字符串中的所有old小串 用new新串替换
                String trim():去掉两端的空格
                int compareTo(String str):按照字典顺序比较字符串
                int compareToIgnoreCase(String str):不区分大小写的按照字典顺序比较字符

猜你喜欢

转载自www.cnblogs.com/AJPFX/p/10891238.html