【Java基础学习 day01】

Java中static、final、volatile、synchronized、transient、strictfp关键字的使用及原理小结

  • 局部变量
  • 类变量(静态变量)
  • 成员变量(非静态变量)

8中内置数据类型   int long short byte double float char boolean

常量 final

操作符

循环结构

 

 类型:

不用引入Integer就可以用

String创建方法:
    1、public String()
    无参构造方法,用来创建空字符串的String对象。
    2、public String(String value)
    用已知的字符串value创建一个String对象。
    3、public String(char[] value)
    用字符数组value创建一个String对象。
    4、public String(char chars[], int startIndex, int numChars)
    用字符数组chars的startIndex开始的numChars个字符创建一个String对象。
    5、public String(byte[] values)
    用比特数组values创建一个String对象。
        byte[] strb = new byte[]{65,66};
        String str6 = new String(strb);//相当于String str6 = new String("AB");
    
常用方法:
    1、求字符串长度
        public int length()//返回该字符串的长度
    2、求字符串某一位置字符
        public char charAt(int index)
    3、提取子串
        public String substring(int beginIndex[, int endIndex])
    4、字符串比较
        1)public int compareTo(String anotherString)//该方法是对字符串内容按字典顺序进行大小比较,通过返回的整数值指明当前字符串与参数字符串的大小关系。若当前对象比参数大则返回正整数,反之返回负整数,相等返回0。
        2)public int compareToIgnore(String anotherString)//与compareTo方法相似,但忽略大小写。
        3)public boolean equals(Object anotherObject)//比较当前字符串和参数字符串,在两个字符串相等的时候返回true,否则返回false。
        4)public boolean equalsIgnoreCase(String anotherString)//与equals方法相似,但忽略大小写。
    5、字符串连接
        public String concat(String str)//将参数中的字符串str连接到当前字符串的后面,效果等价于"+"
            String str = "aa".concat("bb").concat("cc");
            相当于String str = "aa"+"bb"+"cc";
    6、字符串中单个字符查找
        1)public int indexOf(int ch/String str)//用于查找当前字符串中字符或子串,返回字符或子串在当前字符串中从左边起首次出现的位置,若没有出现则返回-12)public int indexOf(int ch/String str, int fromIndex)//改方法与第一种类似,区别在于该方法从fromIndex位置向后查找。
        3)public int lastIndexOf(int ch/String str)//该方法与第一种类似,区别在于该方法从字符串的末尾位置向前查找。
        4)public int lastIndexOf(int ch/String str, int fromIndex)//该方法与第二种方法类似,区别于该方法从fromIndex位置向前查找。
    7、字符串中字符的大小写转换
        1)public String toLowerCase()//返回将当前字符串中所有字符转换成小写后的新串
        2)public String toUpperCase()//返回将当前字符串中所有字符转换成大写后的新串
    8、字符串中字符的替换
        1)public String replace(char oldChar, char newChar)//用字符newChar替换当前字符串中所有的oldChar字符,并返回一个新的字符串。
        2)public String replaceFirst(String regex, String replacement)//该方法用字符replacement的内容替换当前字符串中遇到的第一个和字符串regex相匹配的子串,应将新的字符串返回。
        3)public String replaceAll(String regex, String replacement)//该方法用字符replacement的内容替换当前字符串中遇到的所有和字符串regex相匹配的子串,应将新的字符串返回。
    9、去掉两端的空格
        1)String trim()//截去字符串两端的空格,但对于中间的空格不处理。
        2)boolean statWith(String prefix)或boolean endWith(String suffix)//用来比较当前字符串的起始字符或子字符串prefix和终止字符或子字符串suffix是否和当前字符串相同,重载方法中同时还可以指定比较的开始位置offset。
        3)regionMatches(boolean b, int firstStart, String other, int otherStart, int length)//从当前字符串的firstStart位置开始比较,取长度为length的一个子字符串,other字符串从otherStart位置开始,指定另外一个长度为length的字符串,两字符串比较,当b为true时字符串不区分大小写。
        4)contains(String str)//判断参数s是否被包含在字符串中,并返回一个布尔类型的值。
        5)String[] split(String str)//将str作为分隔符进行字符串分解,分解后的字字符串在字符串数组中返回。

String创建方法:1、public String()无参构造方法,用来创建空字符串的String对象。2、public String(String value)用已知的字符串value创建一个String对象。3、public String(char[] value)用字符数组value创建一个String对象。4、public String(char chars[], int startIndex, int numChars)用字符数组chars的startIndex开始的numChars个字符创建一个String对象。5、public String(byte[] values)用比特数组values创建一个String对象。byte[] strb = new byte[]{65,66};String str6 = new String(strb);//相当于String str6 = new String("AB");常用方法:1、求字符串长度public int length()//返回该字符串的长度2、求字符串某一位置字符public char charAt(int index)3、提取子串public String substring(int beginIndex[, int endIndex])4、字符串比较1)public int compareTo(String anotherString)//该方法是对字符串内容按字典顺序进行大小比较,通过返回的整数值指明当前字符串与参数字符串的大小关系。若当前对象比参数大则返回正整数,反之返回负整数,相等返回0。2)public int compareToIgnore(String anotherString)//与compareTo方法相似,但忽略大小写。3)public boolean equals(Object anotherObject)//比较当前字符串和参数字符串,在两个字符串相等的时候返回true,否则返回false。4)public boolean equalsIgnoreCase(String anotherString)//与equals方法相似,但忽略大小写。5、字符串连接public String concat(String str)//将参数中的字符串str连接到当前字符串的后面,效果等价于"+"String str = "aa".concat("bb").concat("cc");相当于String str = "aa"+"bb"+"cc";6、字符串中单个字符查找1)public int indexOf(int ch/String str)//用于查找当前字符串中字符或子串,返回字符或子串在当前字符串中从左边起首次出现的位置,若没有出现则返回-1。2)public int indexOf(int ch/String str, int fromIndex)//改方法与第一种类似,区别在于该方法从fromIndex位置向后查找。3)public int lastIndexOf(int ch/String str)//该方法与第一种类似,区别在于该方法从字符串的末尾位置向前查找。4)public int lastIndexOf(int ch/String str, int fromIndex)//该方法与第二种方法类似,区别于该方法从fromIndex位置向前查找。7、字符串中字符的大小写转换1)public String toLowerCase()//返回将当前字符串中所有字符转换成小写后的新串2)public String toUpperCase()//返回将当前字符串中所有字符转换成大写后的新串8、字符串中字符的替换1)public String replace(char oldChar, char newChar)//用字符newChar替换当前字符串中所有的oldChar字符,并返回一个新的字符串。2)public String replaceFirst(String regex, String replacement)//该方法用字符replacement的内容替换当前字符串中遇到的第一个和字符串regex相匹配的子串,应将新的字符串返回。3)public String replaceAll(String regex, String replacement)//该方法用字符replacement的内容替换当前字符串中遇到的所有和字符串regex相匹配的子串,应将新的字符串返回。9、去掉两端的空格1)String trim()//截去字符串两端的空格,但对于中间的空格不处理。2)boolean statWith(String prefix)或boolean endWith(String suffix)//用来比较当前字符串的起始字符或子字符串prefix和终止字符或子字符串suffix是否和当前字符串相同,重载方法中同时还可以指定比较的开始位置offset。3)regionMatches(boolean b, int firstStart, String other, int otherStart, int length)//从当前字符串的firstStart位置开始比较,取长度为length的一个子字符串,other字符串从otherStart位置开始,指定另外一个长度为length的字符串,两字符串比较,当b为true时字符串不区分大小写。4)contains(String str)//判断参数s是否被包含在字符串中,并返回一个布尔类型的值。5)String[] split(String str)//将str作为分隔符进行字符串分解,分解后的字字符串在字符串数组中返回。

猜你喜欢

转载自www.cnblogs.com/zhouguanglu/p/10450409.html