Java Foundation for its own weaknesses summary (API, collection)

Source: Internet
Author: User
Tags string format value store

First, some methods in the API

**

Arrays Tool Class

**
1. Concept

Tool classes for array manipulation

2. Member Methods

A) ToString (): public static string toString (data type [] variable name)--turns the array into a string

b) Sort (): public static void sort (data type [] variable name)--Sort the array

c) public static int BinarySearch (int[] arr,int value)--two points find

System class

1, the System class, provides static variables and methods for us to use

2. Member Methods

A) exit ():p ublic static void exit (int value)-Exits the JVM, not 0 indicates an exception exit

b) public static long Currenttimemillis ()-Returns the millisecond value of the current system time

StringBuffer class

1. Concept

String Buffer class

2. Member Methods

a) public int length ()-Number of characters, actual length

b) public int capacity ()-character capacity, theoretical length

c) stringbuffer append (data type variable name)-Add at the end

d) stringbuffer Insert (int index, data type variable name)-Add at specified location

e) stringbuffer deletecharat (int index)-deletes the character at the specified position

f) stringbuffer Delete (int start, int end)-Deletes the specified start position and end
The characters between positions

g) StringBuffer replace (int start, int end, string str)-the contents of the start position to the end position with the specified string, note that the package left does not wrap to the right

Integer class

1. Concept

Packing class for int

2. Member Methods

public static int parseint (string s)-string converted to integer

Conversions between types (String–int)

1. string–> int calls the parseint method in the integer Class (common)
public static int parseint (String s)

2, Int–> String
Method One: Call ToString () in the integer
public static String toString (ITN i);
Method Two: Call the valueof in string
public static String valueOf (int i)
Method Three: Direct and empty string connection
num + "";

Date class

1. Overview

Date represents a specific time, accurate to milliseconds.

2. Construction method, member method

Construction method

Date ()--Specifies the current time by default (common)

Date ——-generates a time based on a given millisecond (common)

Member Methods

Public long GetTime ()-Gets the millisecond value (common)

public void SetTime (long time)-sets the date by millisecond value

SimpleDateFormat Class (Master)

construction methods, member methods
Construction method

SimpleDateFormat ()-No parameter construction method, with default date format (almost unused)

SimpleDateFormat (String pattern)-parameter construction, specifying date format (Common)

Member Methods

Public final String format (date date)-Date –> text (common)

Public Date Parse (String date)-Text –> date

Common pattern strings & combinations

Ii. Collection 1, the origin of the collection

Since we are using object-oriented languages, we want to use objects frequently. And many times, we may need to use a lot of objects, this time, we can only use the previously mentioned array for storage, and the characteristics of the array is fixed length. This is not the case for changing needs. So, Java re-provides a container for storing objects, a container called a collection.

2, the characteristics of the collection

A: Variable Set length
B: Collection can only store reference types
C: Collections can store different types of objects

Differences from arrays (the characteristics of sets and arrays, respectively)
A: The array length is fixed.
B: Arrays can store basic data types, or they can store reference types.
C: The data type of the array storage is consistent.

3. Collection system

1), System diagram
Collection
|–list (elements are ordered, elements can be duplicated)
| –arraylist
| –vector
| –linkedlist
|–set (element unordered, element unique)
|–hashset
|–treeset

Note: Ordered unordered is the consistency of the value store order and the fetch order
(We gather to learn, in fact, learning these APIs, classes and interfaces, but they are related to the regular, so very simple)

2), the origin of the system:
In order to meet the different needs, Java provides us with a variety of collection classes, their data structure is different (explained in detail, in fact, the way the data stored in the different). However, they must have a lot of common things (storage, acquisition, judgment, etc.), through the continuous upward extraction function, and eventually formed a collection of inheritance architecture diagram.

3), System How to learn:
From the top level to learn (first learn the eldest brother, learning the boy), because the top layer is defined as a common method, after learning the top layer, learning the bottom of the time only need to learn the unique method of the bottom, reduce the learning time.

4), How to use:
Usually use the underlying content, because the bottom is the concrete implementation. (We decide which implementation to use according to the specific needs)

5), set use steps
A: Create A Collection Object
B: Create an Element object
C: Adding elements into the collection
D: Traversal using
A: Getting an iterator object from a collection object
B: Judging whether there are elements in the collection by the Hasnext () method of the Iterator object
C: Get through the next () method of the Iterator object

4. Collection interface

1), Common methods:

Boolean Add (Object obj)//Add an element to the collection
void clear ()//deletes all elements in the collection.
Boolean remove (Object obj)//deletes the specified element from the collection
Boolean isEmpty ()//Determines whether the collection is empty.
Boolean contains (Object obj)//Determines whether the specified element exists in the collection.
Iterator Iterator ()//Gets the set iterator object used to traverse the element.
int size ()//Gets the number of elements in the collection

2), less commonly used methods
Object[] ToArray ()//sets the collection into an array.

5. List interface

1), List-specific methods
A: Add Features
void Add (int index, Object obj)//Specify location to add element
B: Delete Feature
Object Remove (int index)//deletes the element according to the specified index and returns the deleted element.
C: Modify function
Object Set (int index, Object obj)//modifies the element at the specified index position to the specified value, returning the value before the modification.
D: Get Features
int indexOf (Object o)//Returns the index of the first occurrence of the specified element in the collection
Object get (int index)//Gets the element at the specified position
Listiterator listiterator ()//list iterator
E: Interception function
List sublist (int fromIndex, int toindex)//intercept collection.

6. iterators

1), what: a traversal of the collection, (can be seen as the bottom of the iterator copy of a set of all elements, the pointer moves to traverse)

2), use of iterators
Iterator it = C.iterator (); Getting an iterator object from a collection object
while (It.hasnext ()) {//Determine if there are elements in the iterator
string s = (string) it.next (); Gets the element and automatically moves to the next location waiting to get
System.out.println (s);
}

3), understand on the line:
(1) Top-level interface collection through the iterator () method, all the collection classes have only one way to get the iterator object;
(2) The iterator is designed as an interface that requires all implementation classes to implement the Judgment Method Hasnext () and the Fetch method next ();
The implementation is implemented through the collection of internal classes, because only the specific set of their own data structure is the most clear, and the method of judging and obtaining the most clear, so that they iterate.
Benefits:
A: Ensure that all collection classes have a common way to get an iterator object (unified)
B: Ensure that all collection classes do not care about the internal implementation, only need to adjust the iterator-related methods on the line.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Foundation for its own weaknesses summary (API, collection)

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.