Java Learning-3 string char char[] int cross-transfer

Source: Internet
Author: User

1. String------>int

1.1 "123"-----> 1, 2, 3

Method 1:

string s =new string (); s= "123"; int i=integer.parseint (s.substring (0,2))//  int i=123int i=integer.parseint ( S.substring (0,1))//  int i=12int i=integer.parseint (s.substring)//  int i=23int i=integer.parseint ( S.substring (0,0))//  int I=1
int I=integer.parseint (s.substring (0,0))//  int I=1

Method 2:

String is converted to char[] and converted to int, which is no longer detailed

  

1.2 "123"------> 123,

string s =new string (), s= "123", int i=integer.parseint (s.substring (0,2))//int i=123 in the case of no more than int value range  

  

2,string--------->char[]

string s =new  string (); s= "123"; Char [] d;d=S.tochararray (); System.out.println (d[1]);

3,char------->int

String s =new= "12345"        ; int i; // i= integer.valueof (s,3); Char [] d;d=S.tochararray (); System.out.println ((int) (d[4]-48));

4,int---------->char

int A=1

Char b= (char) (a+48)

5,int-------->string

int A=1

Char b= (char) (a+48)

Stringc= b+b+b;

Dierzhon

1 "string.valueof (i)
2 "integer.tostring (i)
3 "i+" "

6,int---->char[]

int a = 12345;

Java Learning-3 string char char[] int cross-transfer

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.