Java Get string information

Source: Internet
Author: User
Tags string format truncated

String str = "Hello World"

1, Str.length ();//Get string length

2, Str.indexof (string s);//Find the position of the character in the string, which returns the index position of the first occurrence of the argument string s in the specified string, and when the IndexOf () method of the string is called, the position of S is searched from the beginning of the current string If the string s is not retrieved, the method return value is-1

Example: int size = Str.indexof ("W"); size = 5;

3, Str.lastindexof (string s);//The method is used to return the index position of the last occurrence of the argument string s in the specified string, and when the LastIndexOf () method of the string is called, the position of S is searched from the beginning of the current string. and returns the index position of the last occurrence of S, if the string s is not retrieved, the method return value is-1

Note: When the parameter in the LastIndexOf () method is an empty string "", the return result is the same as the return result of the call length () method

4, Str.charat (int index);//The character at the specified index returns

Example: char Machar = Str.charat (4); Macahr= "O";

5, str.substring (int beginindex);//A string that is truncated at the end of the specified index position

Example: String substr = str.substring (6); substr = "World";

6, str.substring (int beginindex,int endIndex);//A string that is truncated to the end of the index position starting at an index

Example: String substr = str (0,4); substr = "Hello";

7, Str.trim ();//Remove space

8, Str.replace (char Oldchar,char Newchar);//String substitution, return new string

9, Str.startswith (string prefix);//Check whether the string starts with the specified content and returns a Boolean value

10, Str.endswith (string suffix);//Check whether the string ends with the specified content, returns a Boolean value

11, Str.equals (string otherstr);//If two strings have the same character and length, the Equals () method returns True when the method is case-sensitive

12, Str.equalslgnorecase (String otherstr);//Returns a Boolean type but is not case-sensitive when compared

13, Str.compareto (string otherstr);//Compare two strings in dictionary order, the character sequence of an object after the parameter sequence, return a positive integer, return a negative integer before the sequence of the parameter character, return the same as 0

14, Str.tolowercase ();//Change the character in the string from uppercase to lowercase

15, Str.touppercase ();//change all characters in a string from lowercase to uppercase

16, Str.split (string sign);//split string, sign for split character

17, Str.split (String sign,int limit),//sign is a split character, limit is the number of limits

18, String.Format (string Format,object...args);//format is a format string, args is a parameter

19. StringBuilder Builder = new StringBuilder ("");//String generator, which greatly improves the efficiency of frequently increasing strings.

20, Str.append (content);//append character with string generator

21, Str.insert (int offset,arg);//Append to a location in the string generator, offset is the location of the string generator

22, Str.delete (int start,int end);//delete the specified start position in the string to the specified end position

Java Get string information

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.