Java Learning Note--string type conversion

Source: Internet
Author: User

A drop of water in the sea, a grain of sand to see the world

--The Belt and road welcome banquet speech

On the code:

1 Package Cn.stringtoobj;2 3  Public classtypeconversion {4 5      Public Static voidMain (string[] args) {6         //convert string to int7String str ="123";8         int[] INTs =New int[3];9ints[0] =integer.parseint (str);Tenints[1] =integer.valueof (str); Oneints[2] =NewInteger (str); A print (ints); -         //string to byte -         byte[] bytes =New byte[3]; thebytes[0] =byte.parsebyte (str); -bytes[1] =byte.valueof (str); -bytes[2] =NewByte (str); - print (bytes); +         //String Turn short -          Short[] Shorts =New  Short[3]; +shorts[0] =Short.parseshort (str); Ashorts[1] =short.valueof (str); atshorts[2] =NewShort (str); - print (shorts); -         //string goes long -         Long[] longs =New Long[3]; -longs[0] =Long.parselong (str); -longs[1] =long.valueof (str); inlongs[2] =NewLong (str); - print (longs); to         //string to double +         Double[] Doubles =New Double[3]; -doubles[0] =double.parsedouble (str); thedoubles[1] =double.valueof (str); *doubles[2] =NewDouble (str); $ print (doubles);Panax Notoginseng         //string Turn float -         float[] Floats =New float[3]; thefloats[0] =float.parsefloat (str); +floats[1] =float.valueof (str); Afloats[2] =NewFloat (str); the print (floats); +         //String Goto Boolean -str ="true"; $boolean[] Booleans =Newboolean[3]; $booleans[0] =Boolean.parseboolean (str); -booleans[1] =boolean.valueof (str); -booleans[2] =NewBoolean (str); the print (booleans); -         //string goto byte[]Wuyi         byte[] Bytes2 =str.getbytes (); the print (bytes2); -         //string goto char[] Wu         Char[] Dstchars =New Char[Str.length ()]; -Str.getchars (0, Str.length (), Dstchars,0); About print (dstchars); $         //object to String -object[] obj =Newobject[5]; -str =string.valueof (obj); -System. out. println (str); Astr =string.valueof (dstchars); +System. out. println (str); the     } -     Private Static voidPrintChar[] dstchars) { $          for(Chari:dstchars) { theSystem. out. print (i +" "); the         } theSystem. out. println (); the     } -     Private Static voidprint (boolean[] booleans) { in          for(Boolean I:booleans) { theSystem. out. print (i +" "); the         } AboutSystem. out. println (); the     } the     Private Static voidPrintfloat[] floats) { the          for(floati:floats) { +System. out. print (i +" "); -         } theSystem. out. println ();Bayi     } the     Private Static voidPrintDouble[] Doubles) { the          for(Doublei:doubles) { -System. out. print (i +" "); -         } theSystem. out. println (); the     } the     Private Static voidPrintLong[] longs) { the          for(Longi:longs) { -System. out. print (i +" "); the         } theSystem. out. println (); the     }94     Private Static voidPrint Short[] shorts) { the          for( Shorti:shorts) { theSystem. out. print (i +" "); the         }98System. out. println (); About     } -     Private Static voidPrintint[]ints] {101          for(inti:ints) {102System. out. print (i +" ");103         }104System. out. println (); the     }106     Private Static voidPrintbyte[]bytes] {107          for(bytei:bytes) {108System. out. print (i +" ");109         } theSystem. out. println ();111     } the}

Java Learning Note--string type conversion

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.