Set learning notes, set learning notes

Source: Internet
Author: User
Tags addall comparable

Set learning notes, set learning notes

I. Concepts

A set is a way to store objects. The collection contains addresses for convenient reference. JDK 1.2 is available.

Ii. Differences between a set and an array

Set is variable length, and array is fixed length.

Arrays can store basic data types. A set can only store objects. A set can store different types of objects.

 

Collection

1. List: The elements are ordered, repeatable, and indexed.

2. Set: The elements are unordered and cannot be duplicated. They are arranged using hash values.

 

 

 

Iii. CURD

 

Boolean add (E e );

Boolean addAll (Collection <? Extends E> c );

Void clear (); clear the container

Boolean remove (Object o );

Boolean removeAll (Collection <?> C );

Boolean contains (Object o );

 

Iv. iterator

 

The method used to retrieve elements in a set:

ArrayList al = new ArrayList ();
Iterator it = al. iterator (); // Iterator
It. next (); // Return Value
It. hasNext () // boolean Type

Each container has its own storage and retrieval. Each container has a different data structure and may have different access methods.

The fetch method is defined inside the set. The fetch method can directly access the elements inside the set. The fetch method is defined as an internal class.

The data structure of each container is different, so the extracted action details are different. However, they all have common content, that is, judgment and retrieval. In this way, these commonalities can be extracted.

 

 

How can I obtain the object retrieved from the set?

By providing external methods, that is, iterator ();

-------------------------------

V. Set

public interface Set extends Collection

The Set elements are unordered, and the order of storage and removal is not necessarily the same. The elements cannot be repeated. The functions of the Set are the same as those of the Collection.

1. The underlying data structure of HashSet is a hash table. The thread is not synchronous.

HashCode () and equals ()

If the hashcode of the element is the same, the system checks whether equals is true.

If the hashcode of an element is different, equals is not called.

 

Note: For operations such as determining whether an element exists and deleting it, the dependent methods are the hashcode and equals of the element.

HashSet:

 

Demo@c17164

Demo@1fb8ee3

ToString(): getClass().getName() + ‘@’ + Integer.toHexString(hashCode());

2. TreeSet

You can sort the elements in the Set. The thread is not synchronous.

Objects in the TreeSet must be compared.

The underlying data structure is a binary tree;

The basis for ensuring element uniqueness:

CompareTo method, return0

 

The first method of TreeSet sorting:

The Comparable interface must be implemented to override the compareTo method.

Natural sequence of Elements

 

Class Student implements Comparable {

Public int compareTo (Object obj ){

If (! (Obj instanceof Student )){

Throw new RuntimeException ("not a student object ");

}

Student s = (Student) obj;

If (this. age> s. age)

Return 1;

If (this. age = s. age)

Return 0;

Return-1;

}

}

TreeSet only looks at comparTo results

The second sorting method of TreeSet:

When the element itself does not have the comparison, or the comparison is not required, the set itself needs to have the comparison.

When the integration starts, a comparison method is available.

Compare Method

Overwrite the compare method of Comparator

New Integer (s1.getAge (). compareTo (new Integer (s2.getName ()));

 

Vi. List

The List method is unique in this system.

Add (index, element );

AddAll (index, Collection );

Delete: remove (index );

Change: set (index, element );

Query: get (index)

SubList (from, );

ListIterator ();

for(int x = 0; x<al.size();x++){

     sysout();

}

While (it. hasNext ()){

        sysout();

}

List set unique iterator

ListIterator it = new al. listIterator ();

HasNext = true

HasPrevious = false

ListIterator can add, delete, modify, and query objects during traversal.

--------------------------

Common subclass

1. ArrayList: the underlying data structure uses the array structure (JDK1.2)

Features: Fast query speed

Disadvantages: slow increase and deletion (the more elements, the more obvious)

 

2. linked list: the underlying data structure uses a linked list.

Features: insert and delete data blocks

Disadvantage: Slow query speed

Linked List link = new linked list ();

Link. add ();

 

Unique Method of listing:

AddFirst ();

AddLast ();

 

GetFirst ();

GetLast ();

Get element, but do not delete element,

If there are no elements in the collection, NoSuchElementException will appear;

.

 

RemoveFirst ();

RemoveLast ();

Get the element, but the element is deleted,

If there are no elements in the collection, NoSuchElementException will appear;

.

JDK1.6 appears

OfferFirst ();

OfferLast ();

 

PeekFirst ();

PeekLast ();

Get the element, but the element is not deleted,

If no element exists in the Set, null is returned.

 

PollFirst ();

PollLast ();

Get the element, but the element is deleted,

If no element exists in the Set, null is returned.

 

While (! Link. isEmpty ()){

Sop (link. removeFirst ());

}

 

Use equals to compare whether the objects are the same

Public boolean equals (Object obj ){

If (! (Obj instanceof Person )){

Return false;

}

Person p = (Person) obj;

Return this. name. equals (p. name) & this. age = p. age;

}

 

3. Vector: the bottom layer is the array data structure (JDK1.0)

The functions of Vector and ArrayList are the same. The Vector is synchronized, And the ArrayList thread is not synchronized.

Use ArrayList instead of Vector whenever possible

-------------------

Enumeration (JDK1.0)

Enumeration en = v. elements ();

While (en. hasMoreElements ()){

Sysout (en. nextElement ());

}

The enumerated name and method name are too long, so they are replaced by the iterator.


Notes for the high school mathematics collection

Induction of set and function knowledge points
1. The elements in the set are deterministic, unordered, and mutually exclusive.
2. Set nature:
① Any set is its own subset, which is recorded;
② An empty set is a subset of any set and is recorded;
③ An empty set is the real subset of any non-empty set;
If, at the same time, A = B.
If so.
[Note] Z = {INTEGER} (√) Z = {All integers} (×)
It is known that the complement set of A in set S is A finite set, and set A is also A finite set. (×) (for example, S = N; A =, CsA = {0 })
The complete set of empty sets. If set A = Set B, CBA =, CAB = CS (CAB) = D (Note: CAB = ).
3. ① {(x, y) | xy = 0, x, R, y, R} Point Set on the coordinate axis.
② {(X, y) | x <0, x, R, y, R Two, four quadrant point set.
(3) {(x, y) | xy> 0, x, R, y, R} Point Set with three elephant limitations.
[Note]: ① the set of solutions to the equations should be a point set.
Example: the set of solutions {(2, 1 )}.
② The intersection of a point set and a number set is. (for example, A = {(x, y) | y = x + 1} B = {y | y = x2 + 1} Then A then B =)
4. ① the subset of n elements has 2n. ② the real subset of n elements has 2n-1. ③ the non-null real subset of n elements has 2n-2.
5. (1) ① if the negative proposition of a proposition is true, its inverse proposition must be true.
② If a proposition is true, its inverse negative proposition must be true. The original proposition is inverse negative.
Example: ① true proposition is true.
Solution: inverse No: a = 2 and B = 3, then a + B = 5, true, so this proposition is true.
②.
Solution: inverse: x + y = 3 x = 1 or y = 2.
Therefore, it is neither adequate nor necessary.
(2) A small scope is launched; a large scope cannot be pushed out.
For example, if.
6. Three Elements of a function: defined domain, value domain, and corresponding rule.
7. the monotonic interval of a function can be the entire or part of the entire definition field. for a specific function, there may be monotonic intervals, or there may be no monotonic intervals. If a function is a subtraction function in the range (0, 1) and a subtraction function in the range (1, 2, it cannot be said that the function is a subtraction function.
8. Inverse Function Definition: only when the function is satisfied can there be an inverse function. For example, there is no inverse function.
The inverse function of a function is recorded as. In the same coordinate system, the image of the function and its inverse function is symmetric.
[Note]: Generally, the inverse function is an inverse function first, and then three units are shifted to the left. It is an inverse function that is first shifted to three units and then obtained.
9. (1) monotonic functions must have inverse functions, but they are not monotonous when they exist. Therefore, all even functions do not have inverse functions.
(2) If a function has an inverse function and is an odd function, its inverse function is also a strange function.
(3) set the Function y = f (x) to define the fields X and Y. if y = f (x) is an addition (subtraction) function on X, the inverse function must be an addition (subtraction) function on Y, that is, the increase or decrease of the two inverse functions are the same.
(4) In general, if a function has an inverse function, and, that is, the point () is in the function image, and the point () is in the function image.
10. Function Application
Basic Steps for solving function application problems:
Step 1: read and understand the meaning of the question.
To read a question, you must read the text description in the question, understand the actual background of the description, analyze what is known, and find out the corresponding mathematical problems.
Step 2: Introduce mathematical symbols to create a mathematical model.
Generally, set the independent variable to x and function to y. If necessary, introduce other auxiliary variables, and use x, y, and auxiliary variables to indicate the relevant quantities. Then, based on the known conditions, using the knowledge of mathematics, physics, and other relevant knowledge to establish a relational relationship, the actual problem is transformed into a function problem on this basis, to achieve the mathematical problem, that is, to establish a mathematical model.
Step 3: Use the mathematical method to answer the conventional function problem (that is, the mathematical model) and obtain the result.
Step 4: translate the result into a specific answer.
Teaching supplements... the remaining full text>

What kind of software is good for taking study notes?

Both the Mind Map and Wiz are good. Wiz is suitable for web-based Mind Map, which requires a certain degree of knowledge. However, you will find it extremely useful.
 

Related Article

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.