Java Foundation _string

Source: Internet
Author: User

1. Equals, compares string contents, case-sensitive

String S1 = "abc"; String s2 = "ABc"; System.out.println (s1.equals (S2)); --->false

2.equalsIgnoreCase, comparing string contents, case-insensitive

String S1 = "abc"; String s2 = "ABc"; System.out.println (s1.equalsignorecase (S2)); --->true

3.contains, whether the string contains and contains all, case-sensitive

String S1 = "ABCDEF"; String s2 = "F"; String S3 = "F"; System.out.println (S1.contains (S2)); --->truesystem.out.println (s1.contains (S3)); --->false

4.startsWith, determine string start value, case sensitive

String S1 = "ABCDEF"; System.out.println (S1.startswith ("A")); --->truesystem.out.println (s1.startswith ("B", 1)); --->truesystem.out.println (s1.endswith ("F")); --->false

5.isEmpty to determine if it is empty

String S1 = "ABCDEF"; System.out.println (S1.isempty ()); --->false

6.int Length ()

7.char charAt (int index) returns the character of the position from the string

8.int indexof (int ch) Returns the first occurrence of the index

9.int indexOf (String)

10.String subString (int start, (int end)) Intercept string

11.getBytes encoding, converting a string to a character array

String S1 = "ABCDEF"; byte[] arr =s1.getbytes (); for (int i=0;i<s1.length (); i++) {System.out.println (arr[i]);}

Convert a character array to a string

String s2= new String (arr); SYSTEM.OUT.PRINTLN (S2);

12.string replace (char old, char new)

13.string Replace (string old, string new)

14.trim ()

... Not a list of

Java Foundation _string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.