Java basics: 20th conversion between basic java types and strings

Source: Internet
Author: User

 

No matter what method is used, the data entered by the user is in the form of a string, but the input information may need to be used as a number or character during processing, in addition, no matter how the information is stored, it must be displayed as a string. Therefore, conversion between various data types and string types is required. First, the basic data type and String Conversions between type objects: Convert a string to another type: // The conversion between a string and its basic data type Int Is Representative // The followingCodeConverts a string to a number. String input = "111 "; Int I = integer. parseint (input );// Relatively common Int I2 = new INTEGER (input). intvalue (); Int I3 = integer. valueof (input ); Int I4 = new INTEGER (input ); // The following code converts a number to a string String out = new INTEGER (I). tostring (); String out2 = string. valueof (I ); You can use Tostring () Method, all objects have Tostring () Method. If this method does not meet the requirements, you can implement it again. 【 Note: ] An exception may occur when converting a string to a number, so you need to handle the exception. Last time:19th string usage (lower) Next time:21st formatting of numbers Li xucheng csdn blog : Http://blog.csdn.net/javaeeteacher Invite you as a friend:Http://student.csdn.net/invite.php? U= 124362 & C = 7be8ba2b6f3b6cc5

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.