• 基本API方法总结


    ##java_基本API的总结##
    ###类 String方法:###

    1.**substring(int beginIndex, int endIndex) :**返回一个新的字符串,它是此字符串的一个子字符串。

    <font size="2">用法:</font>

        **String sex = id[i].substring(16, 17);** //16位开始,17位结束.

    2.**charAt(int index):**返回指定索引处的 char 值。

    <font size="2">用法:</font>

        **char s=str.charAt(5);**//5指str的下标.

    3.**contains(CharSequence s):**当且仅当此字符串包含 char 值的指定序列时,才返回 true。

    <font size="2">用法:</font>

        String str = "abcdefg";
         System.out.println(str.contains("c"));

    4.**endsWith(String suffix):**测试此字符串是否以指定的后缀结束。

    <font size="2">用法:</font>

         String str="soccer";
         System.out.println(str+"是否以r结尾:"+str.endsWith("r"));

    5.**indexOf(String str):**返回第一次出现的指定子字符串在此字符串中的索引。

    <font size="2"> **用法: 用法同charAt,返回值为int类型.**</font>

    6.**length():** 返回此字符串的长度.
       <font size="2">用法:这里需要注意length和length()的用法</font>

        对于字符串,可以:
        String s = "abcd";
        System.out.println(s.length());  //打印字符串长度
        
        对于数组,length不是方法,而是属性,应该这样:
        String[] aa = {"abc", "123"};
        System.out.println(aa.length);  //注意,没有括号
        
    7.**:replace(char oldChar, char newChar)**返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 而生成的。
     <font size="2">用法:</font>

           String  str="abcdefg"
           String  str1=str1.replace(aa,bb);
        
    8.**toLowerCase():**使用默认语言环境的规则将此 String 中的所有字符都转换为小写。
    <font size="2">用法:</font>
    -
        public static void main(String[] args) 
            {
                String str=" Another day";
                String[] sb=str.split(" ");
                String s=sb[1].toLowerCase();
                System.out.println(s + sb[2]);
            }
    9.**toUpperCase(Locale locale):**使用给定的 Locale 规则将此 String 中的所有字符都转换为大写。
    <font size="2">用法:</font>
    -    
        public static void main(String[] args) 
        {
            String str=" that is it";
            String[] sb=str.split(" ");
            String s=sb[1].toUpperCase ();
            System.out.println(s + sb[2] +sb[3]);
        }
    10.**valueOf(char c):** 返回 char 参数的字符串表示形式。 
    <font size="2">用法:</font>
    -     
          static  String valueOf(char c) 
          //返回 char 参数的字符串表示形式。

  • 相关阅读:
    27、springboot整合RabbitMQ(1)
    26、springboot与消息
    25、springboot与缓存整合Redis
    24、springboot与缓存(2)
    linux之参数实用讲解
    linux之创建临时文件的方法
    【转】linux之shfit
    linux之stat
    Shell 环境中的输入输出重定向
    Linux下samba的安装与配置
  • 原文地址:https://www.cnblogs.com/demoworld/p/3319456.html
Copyright © 2020-2023  润新知