Java Study Notes: common Java string operation functions

Source: Internet
Author: User

[Java]
Package com. yunos. account. controller. api;
 
Import org. apache. commons. lang. StringUtils;
 
 
 
Public class Test {

Public static void main (String [] args ){
String str = "Hello World ";

/* Truncate the string substring */
String string1 = str. substring (5, 10 );
System. out. println (string1 );

/* Connection string concat */
String concatString = "Yes ";
String string2 = concatString. concat (str );
System. out. println (string2 );

/* Replace the string */
String string3 = str. replace ("Hello", "123 ");
System. out. println (string3 );

/* Remove spaces at the beginning and end of trim */
String string4 = "TRIM". trim ();
System. out. println (string4 );

/* Convert to lowercase toLowerCase */
String string5 = "ASODOIASODI". toLowerCase ();
System. out. println (string5 );

/* Convert to uppercase toUpperCase */
String string6 = "asdasdasd". toUpperCase ();
System. out. println (string6 );

/* String length */
Int len = "asdasdasd". length ();
System. out. println (len );

/* Extract a character charAt */
Char ch = "asdasdasd". charAt (6 );
System. out. println (ch );

/* Bytes */
String string7 = "Hello! Hello! ";
Byte [] bytes = string7.getBytes ();
System. out. println (bytes );

/* String to character array */
String string8 = "Hello! Hello! ";
Char [] chs = string8.toCharArray ();
System. out. println (chs. toString ());

/* String comparison function */
If (! Str. equals ("1111 ")){
System. out. println ("different strings ");
}

/* Whether to start with a specific character */
If (str. startsWith ("Hello ")){
System. out. println ("starting with Hello ");
}

/* Whether to end with a specific character */
If (str. endsWith ("World ")){
System. out. println ("end with World ");
}

/* Find the location where the character appears */
Int ddd = str. indexOf ("W ");
System. out. println (ddd );

/* Check whether the string is null """"*/
If (StringUtils. isBlank (str )){
System. out. println ("null ");
}

/* Check that the string is not null. null """"*/
If (StringUtils. isNotBlank (str )){
System. out. println ("null ");
}

/* Check whether the string is null and "" */
If (StringUtils. isEmpty (str )){
System. out. println ("null ");
}

/* Check whether the string is null or "" */
If (StringUtils. isNotEmpty (str )){
System. out. println ("null ");
}

}
}

Package com. yunos. account. controller. api;

Import org. apache. commons. lang. StringUtils;

 

Public class Test {

Public static void main (String [] args ){
String str = "Hello World ";

/* Truncate the string substring */
String string1 = str. substring (5, 10 );
System. out. println (string1 );

/* Connection string concat */
String concatString = "Yes ";
String string2 = concatString. concat (str );
System. out. println (string2 );

/* Replace the string */
String string3 = str. replace ("Hello", "123 ");
System. out. println (string3 );

/* Remove spaces at the beginning and end of trim */
String string4 = "TRIM". trim ();
System. out. println (string4 );

/* Convert to lowercase toLowerCase */
String string5 = "ASODOIASODI". toLowerCase ();
System. out. println (string5 );

/* Convert to uppercase toUpperCase */
String string6 = "asdasdasd". toUpperCase ();
System. out. println (string6 );

/* String length */
Int len = "asdasdasd". length ();
System. out. println (len );

/* Extract a character charAt */
Char ch = "asdasdasd". charAt (6 );
System. out. println (ch );

/* Bytes */
String string7 = "Hello! Hello! ";
Byte [] bytes = string7.getBytes ();
System. out. println (bytes );

/* String to character array */
String string8 = "Hello! Hello! ";
Char [] chs = string8.toCharArray ();
System. out. println (chs. toString ());

/* String comparison function */
If (! Str. equals ("1111 ")){
System. out. println ("different strings ");
}

/* Whether to start with a specific character */
If (str. startsWith ("Hello ")){
System. out. println ("starting with Hello ");
}

/* Whether to end with a specific character */
If (str. endsWith ("World ")){
System. out. println ("end with World ");
}

/* Find the location where the character appears */
Int ddd = str. indexOf ("W ");
System. out. println (ddd );

/* Check whether the string is null """"*/
If (StringUtils. isBlank (str )){
System. out. println ("null ");
}

/* Check that the string is not null. null """"*/
If (StringUtils. isNotBlank (str )){
System. out. println ("null ");
}

/* Check whether the string is null and "" */
If (StringUtils. isEmpty (str )){
System. out. println ("null ");
}

/* Check whether the string is null or "" */
If (StringUtils. isNotEmpty (str )){
System. out. println ("null ");
}

}
}

 

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.