Java.util

xiaoxiao2021-03-05  51

Interface

COLLECTION

RetainalL: Keep two collection of Collection. Note that if the collection is converted by arrays.aslist, then this method will fail. This method is not supported because the conversion List interface does not support this method

Samples:

Public Static Void CollectionTest ()

{

Collection c1 = new arraylist ();

Collection C2 = New ArrayList ();

C1.Add ("AAA");

C1.Add ("bbb");

C1.Add ("CCC");

C2.Add ("DDD");

C2.Add ("CCC");

C2.Add ("eee");

Boolean isretainsucceed = false;

IsretainSucceed = C2.Retainal (C1);

System.out.println ("isretainsucceed =" isretainsucceed;

System.out.println ("********** stout collection c2 values");

Iterator it = c2.iterator (); it.hasnext ();)

{

String s = (String) ore.next ();

System.out.println ("s =" s);

}

}

ENUMERATION

Too simple, reference documentation

Comparator

Not used

EventListener

Air interface

Iterator

And the different points of Enumeration:

1. Remove objects when you are traversing Collection

2. Method is better name readability

List

Four categories: AbstractList, ArrayList, LinkedList, Vector

List features:

1. Allow duplicate elements to allow NULL elements

2. It is recommended to use Iterator traversal instead of indexing

Addall: Join Collection

ContainSall: Whether to include Collection

Retainall: Reserved and Collection

Sublist: Returns a child list that specifies the index interval

Listiterator:

1. Provide two-way traversal of elements, rather than one-way

2. Change the stored elements over time

3. Dynamically inserted into elements, inserted elements on the previous position of the current operation element

Samples:

Public static void Listtest () {

System.out.println ("********** listtest basp:");

List list = new arraylist ();

List.add ("aaa");

List.add ("bbb");

List.Add ("CCC");

Listiterator it = list.listiterator ();

System.out.println ("*************** ITERATING LIST Forward:");

While (ore.hasnext ()) {

String s = (String) ore.next ();

System.out.println ("********** element =" s);

System.out.println ("************************ ITERATING LIST BACKWARD:");

While (item.hasprevious ()) {

String s = (String) it.previous ();

System.out.println ("********** Element =" s);

}

System.out.println ("************************* ADD Element Into List:");

While (ore.hasnext ()) {

INT i = iter.nextindex ();

IF (i == 2)

iTer.Add ("DDD");

String s = (String) ore.next ();

System.out.println ("********** Element =" s);

}

System.out.println ("*************** ITERATING LIST Backward After ADD ELEMENT:");

While (item.hasprevious ()) {

String s = (String) it.previous ();

System.out.println ("********** Element =" s);

}

System.out.println ("********** listtest end:");

}

Map

Keyset:

Return the SET object, then you can traverse this set. Each element of it is a Map.Entry object

Map.Entry.SetValue:

When traversing the Entry object, you can change the value value corresponding to the key.

Samples:

Public static void mapENTRYSETTEST () {

System.out.println ("********** mapENTRYSETTEST BEGIN:");

Map map = new hashmap ();

Map.put ("first", "aaa");

Map.put ("SECOND", "BBB");

Map.put ("third", "ccc");

Map.put ("Fourth", "DDD");

SET set = map.entryset ();

Map.Entry entry = null;

System.out.println ("********** Print VALUES IN MAP:");

Iterator it = set.iterator (); it.hasnext ();) {

Entry = (Map.Entry) iter.next ();

System.out.println ("key is:" entry.getKey () "and value is:" entry.getValue ());

Entry.SetValue (String) entry.getValue () "_setValuetest");

}

System.out.println ("********* AFTER SET VALUE, ITERATING VALUES IN MAP:"); for (Iterator Iter = set.ITerator (); it.hasnext ();) {

Entry = (Map.Entry) iter.next ();

System.out.println ("key is:" entry.getKey () "and value is:" entry.getValue ());

}

System.out.println ("********** mapENTRYSETTEST END:");

}

Observable and Observer

I haven't thought about it yet

Randomaccess

Empty interface. Realize the List implementation of this interface, indicating that they support high-speed random access elements. If this interface is realized, theory

For (int i = 0, n = list.size (); i

List.get (i);

Fast than the following code:

Iterator i = list.iterator (); i.hasnext ();)

i.next ();

SET:

Nothing special, and Collection is almost

转载请注明原文地址:https://www.9cbs.com/read-34621.html

New Post(0)