Java Learning Note (2015.7.27~7.31)

Source: Internet
Author: User

Java Learning Note (2015.7.27~7.31) Java Learning Note (2015.7.27~7.31)

Java课堂

  • Java Learning Note (2015.7.27~7.31)

      • Little Tricks

      • Common methods

      • 1, list another sub-class--linkedlist

      • 2. Common methods of arrays

      • 3. Sorting

      • 1. Find by dichotomy

      • 2. Array conversion to List

      • 3. variable parameter type ... param (learn)

      • 1. Container Collection

      • 2, Automatic disassembly box (learn)

      • 3. JDK Enhanced for loop (learn)

      • 4. Generic type (Master)

      • 5. Differences between iterator and for in iterations

      • 1. Concept: An object that holds multiple objects.

      • 2. Why does the JDK provide the container

      • 3. API

      • 4, the function of the container

      • 5. Common methods of collection interface

      • 6. Operation between containers (learn)

      • 7, List of features

      • 8. Features of Set

      • 9. ArrayList automatically increase or decrease the element's strategy (learn)

      • 10. Map (Learn)

      • 11. Iteration

      • 1. Plastic Surgery

      • 2, the conversion of the value

      • 3, the procedure of the Organization

      • 4. FAQ for method rewriting

      • Day16

      • Day18

      • Day19

      • Weekend Assignments

Day16

Review

1. Plastic Surgery

The basic unit of data is bit (bit).

type bit Kb Range
Byte 8 Guests 1 bytes -128~127 (2^8)
Short 16 Guests 2 bytes -32768~32767 (2^16)
Int 32 Guests 4 bytes Very big, slightly
Long 64 guests 8 bytes Ash is often large, slightly
2, the conversion of the value

Char is converted to int by using ASCII (English pronunciation/ski/).

3, the procedure of the Organization

Order
Branch
Cycle

4. FAQ for method rewriting
    • Duplicate Method Study () in Type Student class
      Method repeats.

    • The constructor Student () is undefined
      Construction method Not defined

    • Constructor call must is the first statement in a Constructor
      The This () call overload (overload) Construction method must be in the first row

    • The static field Chinese.guoji should be
      Accessed in a static
      Static Call static

Day181, Container Collection1, Concept: An object that holds multiple objects. 2. Why does the JDK provide the container

Features that almost all programmers need

3. API

Application Interface Application Programming Interface

4, the function of the container
    • Same as Array

    • Automatically increases or decreases the length of the container

5. Common methods of collection interface
    • int size ();

    • Boolean isEmpty ();

    • void Clear ();

    • Boolean contains (Object element);

    • Boolean Add (Object element);

    • Boolean remove (Object element);

6. Operation between containers (learn)
    • Boolean cotainsall (Collection c);

    • Boolean addadd (Collection c);

    • Boolean RemoveAll (Collection c);

    • Boolean retainall (Collection c);

7, List of features
    • Store in order of preservation

    • Elements can be repeated

8. Features of Set
    • Do not store in the order in which they are saved, according to their specific order

    • HashSet internal elements sorted by Hashcode value

    • The element cannot be Hongfu

9. ArrayList automatically increase or decrease the element's strategy (learn)

The internal implementation of ArrayList uses an array, if the number of elements is less than 10, the array size is 10, if it is greater than 10, then the original length + half of the original length

10. Map (Learn)
    • Saving data in the form of key-value pairs

    • Example: Student number and name

    • When you save an element, the value is overwritten if key is the same

    • Key is unique and does not allow duplication

11. Iteration
    • Each container implements the iterator interface

    • There are only three methods:

      • Boolean hasnext ();

      • Object next ();

      • void Remove ();

    • Iterate Code Snippets:

Iterator ITR = C.iterator (); while (Itr.hasnext ()) {Itr.next ();}
2, Automatic disassembly box (learn)

Autoboxing/autounboxing

Basic Type Package Type
Byte Byte
Short Short
Int Integer
Long Long
Float Float
Double Double
Char Character
Boolean Boolean
    • Character wrapper class Judging whether it is a number or a letter

Boolean digit = Character.isdigit (' 4 '); SYSTEM.OUT.PRINTLN (digit); Boolean letter = Character.isletter ('! '); SYSTEM.OUT.PRINTLN (letter);
3. JDK Enhanced for loop (learn)
for (Object str:list) {System.out.println (str);}        for (int i = 0; I<list.size (); i++) {String str = (string) list.get (i); System.out.println (str);}
4. Generic type (Master)
    • Guaranteed type Safety

    • Type casts are not required when fetching data

list<string> list = new arraylist<string> () List.add ("AAA"); List.add (12);//error, type mismatch
5. Differences between iterator and for in iterations
    • Iterator iteration, the object of iteration has only one time;

    • For is not this start, repeat several times can.

Day191, list another subclass--linkedlist
    • Storage performance

subclass Add Delete check
ArrayList low low high High
linkedlist high high low low
    • The physical structure, the bottom of the ArrayList is an array, and the bottom of the LinkedList is the linked list.

      • Arrays: Fixed number of elements, continuous space

      • Linked list: The number of elements is not fixed, space is not continuous

    • Functional angle: Queue (heap), stack, tree (Learn)

      • Queue: Normal mode, FIFO (First Out)

      • Stack: LIFO, * * * Clip mode (last in first out)

      • Tree: Ordered binary tree, in a branch, the left node is the smallest, the right node is the largest.

      • Push: Pressed into the stack

      • Pop: The top element of the stack pops up (the last to come in to the eject)

    • ArrayList Why are there two remove methods?
      A: Remove (object o) is collection, and remove (int index) is a new addition to the subclass because ArrayList is based on an array, so the subscript is possible.

2, array of common methods 1, two-way search

Premise: The array must be ordered

Arrays.binarysearch (Arrays,key)
2. Array conversion to List
List aslist = Arrays. Aslist (1,2,3,4,5);
3. variable parameter type ... param (learn)

Mutable parameters are implemented in an array, so it is not possible to override the method with an array as a formal parameter.

3. Sorting

Ideas:

    • Enables the current class to implement the comparable interface, increasing the ability to compare with other similar objects

Class Student implements comparable<student> {private int id;        private String name;        public int compareTo (Student o) {return this.id-o.id; }}
    • Find other objects with comparable ability to compare
      1. Create a class that implements the comparator interface, which is used to compare the size of each two student and to pass in a custom comparator object when sorting.

Class Studentcomparator implements comparator<student>{public int compare (Student O1, Student O2) {        return o1.id-o2.id; }}...... comparator<student> Comparator = new Studentcomparator (); Collections.sort (List,comparator);
Weekend Homework Tips

Convert a character to a number
For example, converting ' 1 ' to shaping 1

int a = integer.valueof (' 1 ' + "")

So we can turn it into 1 smoothly.

Common methods
    • Method of CharAt () string
      String name. CharAt (index) to remove characters from the string

    • Collections.frequency (Collection C, Object O)
      Returns the number of elements in the specified collection that are equal to the specified object.

Java Learning Note (2015.7.27~7.31)

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.