Java imminent data transformation

xiaoxiao2021-03-05  21

1.int-> short

Exp: short shortvar = 0; int int.com = 0; shortvar = (short) Intvar

2. SHORT -> INT Exp: short shortvar = 0; int int.com = 0; intvar = shortvar;

3. INT-> String Exp: int INTVAR = 1; string stringvar; stringvar = String.Valueof (intvar);

4. float-> string exp: float floatvar = 9.99f; string stringvar; stringvar = String.Valueof (floatvar);

5. Double-> string exp double doublevar = 99999999.99; string stringvar; stringvar = String.Valueof (doublevar);

6. Char-> string exp char charvar = 'a'; string stringvar; stringvar = String.Valueof (Charvar);

7 string-> int, float, long, double exp String INTSTRING = "10"; string floatstring = "10.1f"; string longstring = "9999999"; string doubleString = "9999999.9";

INT i = integer.parseint (INTSTRING); float f = integer.parseint (floatstring); long Lo = long. PARSEINT (longstring); double d = double. Parseint (doubleString);

8 string-> byte, short exp String s = "0"; byte b = integer.intValue (s); short sh = integer.intValue (s);

9 string-> char exp String s = "abc"; char a = s.charat (0); return character A

10 string -> boolean string s = "true"; boolean flag = boolean.valueof ("s");

Long -> int, int -> long This basic type forced conversion can be int I = 1; long L = (long) i; double d = (double) i;

Date (date) ----------> string (character) Date D = new date (); string ss = d.tolocalestring (); orsimpledateformat format = new SimpleDateFormat ("YYY-MM-DD HH: mm: ss "); string ss = format (d);

转载请注明原文地址:https://www.9cbs.com/read-37637.html

New Post(0)