Java Collection comparison ---- collection, java ---- Collection
I have never figured out the differences between various java collections before, so I will combine them here for comparison.
Collection and Map
All java collections come from one of the Collection and Map inte
Collection Interface OverviewThe root interface in the Collection hierarchy. Collection represents a set of objects, also known as Collection elements. Some collection allow duplicate elements, while others do not. Some of the collection
1. Collection collection stores strings and iterates throughAnalysis:(1) Creating a Collection Object(2) Creating a String Object(3) Adding a String object to the collection(4) Traversing the collection2. code example:1 Packagecn.itcast_04;2 3 Importjava.util.ArrayList;4 Importjava.util.Collection;5 ImportJava.util.It
The methods in java collection _ collection are embodied through Arraylist, And the java collection arraylist
Import java. util .*;/*Collection defines the common functions of the Collection framework.1. AddAdd (e );AddAll (collection
Steps to use for the collection:(1) Creating a Collection Object(2) Creating an Element object(3) Adding elements to the collection(4) Traversing the collection:• Get an Iterator object from a collection object• Determine if there are elements through the Hasnext () method o
Traversal of the 1.Collection collectionThe collection collection is not directly traversed, so we have to be able to traverse it indirectly, we know the array is easy to implement the variable, we can do this:Use object[] ToArray (): Converts a set into an array, enabling the collection to traverseCode implementation:
Talk about the collection method
1, such as we enter the space to QQ, and then we have the following force to click the Green box shown in the section to enter the "details" open into
2, after the entry and then click "Details" to find the details of the interface of the "collection", click it can
3, OK now you will see a "collection success" h
Collection interface member MethodsObject[] ToArray ()The collection can be traversed by transferring the set to the array.Iterator Iterator ()Iterators, private traversal of collectionspackagecn.itcast_01;importjava.util.arraylist;importjava.util.collection;/** Traversal of the collection. It is actually getting each element in the
1. Why is an iterator not defined as a class but defined as an interface?A: Suppose the iterator defines a class so that we can create an object of that class and invoke the method of that class to implement the traversal of the collection. But what? We think that there are a lot of collection classes available in Java, and the data structures of these collection
1. Case of HashMap Collection (hashmapHashmapKey: StudentRequirement: If the member variable values for two objects are the same, then the same object.Value: StringHashMap is the most commonly used map collection, and its key-value pairs are stored with the hash code of the key to determine where the value is placed.An object that is a key in HashMap must override the Hashcode () method of object and the Eq
Java garbage collection (2) Generational garbage collection of heap memory and java garbage collectionHeap memory generation collection
Java divides the heap garbage collection into three smaller parts: the new generation, the old generation, and the persistent generation. The new generation mainly uses the replication
1 PackageCom.pang.jihe_demo;2 3 Importjava.util.ArrayList;4 Importjava.util.Arrays;5 Importjava.util.List;6 7 Public classDemo01 {8 Public Static voidMain (string[] args) {9 //Collection-to-array, only reference data types can be loaded in the collectionTenarraylistNewArraylist(); OneList.add (12); AList.add (11); -List.add (9); -object[] Array =List.toarray (); the System.out.println (arrays.tostring (array)); - //Array to
1. JavaSE _ Collection (simple Collection, Collection, List) and javasecollection
Set (1)1. simple understanding of Collections
1. Ridicule
Collections, to put it bluntly, are data storage. Remember that in OOP, we once said that OOP puts data first and then considers the algorithm for operating data. That is to say, we will not talk about the data structure. A s
ImportJava.util.*;/*removes duplicate elements from the ArrayList collection. */classArraylisttest { Public Static voidsop (Object obj) {System.out.println (obj); } Public Static voidMain (string[] args) {ArrayList Al=NewArrayList (); Al.add ("Java01"); Al.add ("Java02"); Al.add ("Java01"); Al.add ("Java02"); Al.add ("Java01");//Al.add ("java03"); /*the next call in the loop in the iteration is hasnext judged once. Iterator it = Al.i
1. HashMap collection (The key is an Integer, the value is a case of String )2. code example:1 Packagecn.itcast_02;2 3 ImportJava.util.HashMap;4 ImportJava.util.Set;5 6 /*7 * hashmap8 * Key: Integer9 * Value: StringTen */ One Public classHashMapDemo2 { A Public Static voidMain (string[] args) { - //To create a collection object -HashmapNewHashmap(); the - //creating elements and add
Java Collection comparison ---- collection (continued), java ---- Collection
Set Interface
The Set interface is rarely mentioned in class, so there are not many understandings of it. The elements in the class that implement the set interface are not repeated. It depends on map. In fact, the saved value is the saved key. In map, the key will not be repeated, so th
The scenario is this: there is a collection of suppler under order, that is, there may be multiple vendors under an order; supplier has a collection of product, which is the purchase of multiple products from one vendor.The demand is this: figure out the total price of all ordered productsModel This way: Public classOrder { Public intOrderId {Get;Set; } PublicIcollectionGet;Set; } PublicOrder () {Supp
1. Collection iterator:1 Iterator Iterator (): iterator, private traversal of the collection2. code example: Packagecn.itcast_03;Importjava.util.ArrayList;Importjava.util.Collection;ImportJava.util.Iterator;/** Iterator Iterator (): iterators, private traversal of collections* Iterator (iterator): * Object Next (): Gets the element and moves to the next position . * Nosuchelementexception: No such element, because you have found the last. * Boolean H
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.