Java Day 16

Source: Internet
Author: User

Basic data Type wrapper class
Integer.max_value

Integer.parseint ();

Intvalue ();

ValueOf ();

Automatic loading and unpacking
If it is a byte range, the data is shared

Sorting numeric values in strings
"20 23 4 5 6-8 0 88"

1  PackageCom.company;2 3 Importjava.util.Arrays;4 Importjava.util.Objects;5 6 /**7 * Created by Junius on 2016/10/2.8 * 1. Change string to string array9 * 2, the character array into an int arrayTen * 3, sort int array One * 4, the sorted array into a string array A  */ -  Public classTest001 { -     Private Static FinalString space_string= ""; the      Public Static voidMain (string[] args) { -  -String numstr = "20 23 4 5 6-8 0 88"; - System.out.println (NUMSTR); +Numstr =Sortstringnumber (NUMSTR); - System.out.println (NUMSTR); +     } A  at      Public Staticstring Sortstringnumber (String numstr) { -string[] Str_arr =StringToArray (NUMSTR); -         int[] Num_arr =Stringtoint (Str_arr); - Mysort (Num_arr); -String temp =arraytostring (Num_arr); -         returntemp; in     } -  to      Public StaticString arraytostring (int[] num_arr) { +StringBuilder SB =NewStringBuilder (); -          for(inti = 0; I <num_arr.length; i++) { the             if(i!=num_arr.length-1){ *Sb.append (num_arr[i]+space_string); $}Else {Panax Notoginseng sb.append (Num_arr[i]); -             } the         } +         returnsb.tostring (); A     } the  +      Public Static voidMysort (int[] num_arr) { - Arrays.sort (Num_arr); $     } $  -      Public Static int[] Stringtoint (string[] str_arr) { -         int[] Num_arr =New int[str_arr.length]; the          for(inti = 0; I <str_arr.length; i++) { -Num_arr[i] =Integer.parseint (Str_arr[i]);Wuyi         } the         returnNum_arr; -     } Wu  -     Private Staticstring[] StringToArray (String numstr) { About         returnNumstr.split (space_string+ "+"); $     } -  -  -}
View Code

Collection Class
Objects encapsulate unique data and require containers for more objects
1. Storage objects
2. Variable length
3. Do not store basic data types

1. Add
2. Delete
3. Judgment
4. Get

Iterators

List set
List ordered repetition
Set does not repeat unordered

List method
Add
Remove
Set
Get
Index
LastIndexOf

Listiterator
Iterator limitations in iterators, do not use the collection manipulation elements

1  Public classListdemo {2      Public Static voidMain (string[] args) {3List List =NewArrayList ();4List.add ("ABC1");5List.add ("ABC2");6List.add ("ABC3");7List.add ("ABC4");8 9Listiterator it =list.listiterator ();Ten          while(It.hasnext ()) { OneObject obj =It.next (); A             if(Obj.equals ("ABC2")){ -It.set ("Abc9"); -}Else theSystem.out.println ("Next:" +obj); -         } - System.out.println (list); -     } +}

List
Vector--The internal array data structure is synchronous
ArrayList----out of sync, inside is the array data structure
linkedlist--internal is linked list data structure, non-synchronous, adding and deleting elements of speed quickly

Java Day 16

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.