String Functions in Java __string

Source: Internet
Author: User
Tags string functions in java

Some of the commonly used string functions in Java are recorded for later use.

1 java.lang.string-->substring (int indexid)/string substring (int beginidex,int endindex)
Get substring: "Unhappy". Substring (2)--> "Happy" (intercept string from IndexID start to end)
"Emptiness". Substring--> "" (Return empty string)
"Hamburger". Substring (4,8)--> "Urger"
"Hamburger". Substring (4,20)--> "Java.lang.StringIndexOutOfBoundsException" exception
The same usage is used for java.lang.stringbuffer/stringbuilder.
2 Java.lang.string.c[color=green]oncat (String appendstr) [/color] tail connector substring
"Cares". Concat (s)--> "Caress"
"". Concat ("Hello")--> "Hello"
' To '. Concat ("get"). Concat ("her")--> "Together"
This method is only available in the String class
3 java.lang.String.charAt (int index): char (the letter corresponding to the position according to index)
"Hello". CharAt (4)--> ' O ' may throw an exception indexoutofboundsexception
4 Java.lang.String.lenght () This is nothing to say, but don't forget the array object does not have this function
5 java.lang.String.contentEquals (StringBuffer compstr): Boolean
Returns True if the comparison string is exactly the same as the contents of the COMPSTR
6 Java.lang.String.startsWith (String prefix): boolean
Java.lang.String.endsWith (String suffix): boolean
To determine whether a string begins and ends with strings
7 java.lang.String.indexOf (String str)/lastindexof (String str)
Get the first/last match to the location of STR
8 Java.lang.String.split (String regEx): string[]
To cut a string based on the regex of a regular expression
9 java.lang.String.toUpperCase ()/tolowercase the strings into uppercase/lowercase
Java.lang.String.toCharArray (): char[] Break a string into a character array
One public String intern () if and only if String1.equals (string2)
The public String replaceall (string regex,string Replacement)/replacefirst (string oldstr,string newstr)
Replace string
Java.lang.String.trim () Removes both ends of the string spaces

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.