String-type String to remove space data type conversion (String to int), stringint

Source: Internet
Author: User

String-type String to remove space data type conversion (String to int), stringint

// Initial string
String a = "1 2 3 4 5 ";
System. out. println ("string:" + );
System. out. println ();

// Use the trim method of String to remove the String with spaces at the beginning
String B = a. trim (); // trim spaces at the beginning and end of the trim () function
System. out. println ("Remove the beginning:" + B );
System. out. println ();

// Replace all spaces with the String replace Method

// ReplaceAll replaces all replaceFirst
String c = a. replaceAll ("", ""); // replace all spaces in the String with replace
System. out. println ("Remove all spaces:" + c );
// Use the String replace method to replace the String with spaces
String d = a. replaceFirst ("", ""); // replace the space at the beginning of the String with replace
System. out. println ("Remove the beginning:" + d );
System. out. println ();

// Convert String to int
Int I = Integer. parseInt (c );
System. out. println ("int type:" + I );
System. out. println ();

// String to int post-Multiplication
Int j = I * 2;
System. out. println ("multiply by 2:" + j );

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.