String总结-部分

Modifier and Type

Method and Description

 char

charAt(int index)
        
  Returns the char value at the specified index.

public class TestCharAt {

         public static void charAt(int index) {

           

         }

  

   public static void main(String[] args) {

            String a="sophie";

            char c=a.charAt(1);

            System.out.println(c);

   }

}                                                               //this method can be read as char at index

 int

codePointAt(int index)
        
Returns the character (Unicode code point) at the specified index.

public class Test2 { 

     

public static void main(String[] args) {

         String a="sophiea";

         int c=a.codePointAt(6);        //charAt is the same result 97

         System.out.println(c);

}

}

int

codePointBefore(int index)
          
Returns the character (Unicode code point) before the specified index

public class Test2 { 

     

      public static void main(String[] args) {

                String a="sophieaa";

                int c=a.codePointBefore(7);

                System.out.println(c);

      }

}                                                    //result is 97

int

codePointCount(int beginIndex, int endIndex)
          
Returns the number of Unicode code points in the specified text range of this String.

public class Test2 { 

     

      public static void main(String[] args) {

                String a="sophie";

                int c=a.codePointCount(0,0);

                System.out.println(c);

      }

}                                                        //result is 0

int

compareTo(String anotherString)
          
Compares two strings lexicographically. 字典顺序向量

public class Test2 { 

     

      public static void main(String[] args) {

                String a="sophie";

                int c=a.compareTo("howard");

                System.out.println(c);

      }

}

 int

compareToIgnoreCase(String str)
          
Compares two strings lexicographically, ignoring case differences.

 String

concat(String str)
         
 Concatenates the specified string to the end of this string.

public class Test2 { 

     

      public static void main(String[] args) {

                String a="sophie";

                String b="love";

                String c=b.concat(a);

                System.out.println(c);

      }

}                                                          //result is loves

boolean

contains(CharSequence s)
          
Returns true if and only if this string contains the specified sequence of char values.

public class Test2 { 

     

      public static void main(String[] args) {

                String a="good study";

                boolean b=a.contains(" ");

                System.out.println(b);

      }

}                                                          //result is true

 boolean

contentEquals(CharSequence cs)
         
 Compares this string to the specified CharSequence.

public class Test2 { 

     

      public static void main(String[] args) {

                String a="good study";

                boolean b=a.contentEquals("good study");

                System.out.println(b);

      }

}

static String

copyValueOf(char[] data)
          Returns a String that represents the character sequence in the array specified.       
?

 

boolean

endsWith(String suffix)
          Tests if this string ends with the specified suffix.

public class Test2 { 

 

      public static void main(String[] args) {

                String a="good";

                boolean b=a.endsWith("od");

                System.out.println(b);

      }

}                                                                   //true

 

int

indexOf(int ch, int fromIndex)
          Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

 int

indexOf(String str)
          Returns the index within this string of the first occurrence of the specified substring.

 int

indexOf(String str, int fromIndex)
          Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

public class Test2 { 

 

      public static void main(String[] args) {

                String a="good day today";

                int b=a.indexOf('t',5);

                System.out.println(b);

      }

}

 

public class Test2 {

 

       public static void main(String[] args) {

                  String a="good day today";

                  int b=a.indexOf("today");

                  System.out.println(b);

       }

}

public class Test2 { 

 

      public static void main(String[] args) {

                String a="good day today";

                int b=a.indexOf("day",9);

                System.out.println(b);

      }

}

             

public class Test2 { 

 

      public static void main(String[] args) {

                String a="good day today";

                String b=a.toUpperCase();

                String c=b.toLowerCase();

                System.out.println(b);

                System.out.println(c);

      }                                       //GOOD DAY TODAY good day today

}

 

 String

substring(int beginIndex)
          
Returns a new string that is a substring of this string.

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值