Today we talk about the use of collections and common collection types in Java.What is a collection?Just recently the school inside military training, only heard the instructor shouted: "Set!!!" "You little moe new people on the fart of the run came up neatly arranged, this is the collection ...The collection in Java is also the same meaning, Java a shout: "Collection!!!" ", then we put the data that needs to be put together in a set. Some people will
1 Set set: is a set of unordered and non-repeating elements, fast access, solve the problem of duplication;S2 = set (["Che", "Liu", "haha"])Add (): Adds an element;Difference (): Creates a new set with the difference between the previous set and the latter, without changing the current set;Difference_update (): Removes the specified element from the collection, changes the current collection, and does not generate a new collection;Intersection (): Takes the intersection, generates a new set;Inte
implementing a game of chance. For example, it can be used to mix a List of card objects that represent a deck of cards. In addition, it is also useful when generating test cases.Collections.shuffling (list)Double array[] = {112, 111, 23, 456, 231};for (int i = 0; i List.add (New Double (Array[i]));}Collections.shuffle (list);for (int i = 0; i System.out.println (Li.get (i));}Results: 112,111,23,456,2313) Inversion (Reverse)Use the reverse method to sort the specified list in descending order b
copy the original list, create a larger list, and then destroy the original list. At append, the compiler pre-creates a subset of the data space for future additions. When a tuple is merging (+), a new tuple is created, and then the old tuple is destroyed, and the tuple dataset does not change before or after the groupDictionaries and collectionsDictionaries and collections are suitable for storing data that can be indexed. When you use dictionaries
ObjectiveJava provides a tool class for manipulating set, list, and map collections: Collections, a tool class that provides a number of ways to sort, query, and modify collections.It also provides methods for placing the collection object immutable, synchronizing control of the collection object, and so on.This class does not need to create objects, and internally provides static methods.I. Overview of Col
to COLL111.coll1.equals (Collection coll2);12.hashCode ();13.Object obj = Coll.toarray ();//convert collection to array14.iterator ();//Returns an Iterator interface implementation class object for collection collection traversal (cannot traverse map)2. Traversal of the collection:1. Using Iterator iterator implementation: Iterator ite = Coll.iterator (); while (Ite.hasnext) { System.out.println (Ite.next ());}2. Use the enhanced for loop to implement traversal of
First, set (collections)Java uses collections to organize and manage objects.1. The collection Class of JavaThe collection class is primarily responsible for saving, holding, and managing objects, so the collection class is also known as a container class.The collection class is divided into set, List, map and queue four systems.
Set represents unordered, non-repeating set;
The List represents
Chapter II: The Use of collections
We often use a variety of collections, numbers, strings, and objects. They are everywhere, even if the code to operate a set can be slightly optimized, it can make the code a lot clearer. In this chapter, we explore how to use lambda expressions to manipulate collections. We use it to iterate over the collection, to transform t
This series of articles translates from functional programming in Java Venkat Subramaniam
Chapter II: The use of collections
We often use a variety of collections, numbers, strings, and objects. They are everywhere, even if the code to operate a set can be slightly optimized, it can make the code a lot clearer. In this chapter, we explore how to use lambda expressions to manipulate
fast failing
Starting with the Java 2 Platform v1.2, this class is improved to implement the List interface, making it a member of the Java collections Framework. Unlike the new collection implementations, vectors are synchronized enumset underlying data structures
Hash list Description
A private Set implementation that is used with an enumeration typeThe iterators returned by the iterator method traverse these elements in their natural order, which
Static sort APIs in the 1,arrays class
The sort in Arrays.sort (int[] a) is a quick sort, with a time complexity of O (NLOGN)
Arrays.sort (t[],comparator , arranged in natural order when C=null
2,collections static sort api,collections are stable.
Collections.sort (list , do not know what sort of method, the source can not see
3,arraylist Sorting API
LIst.sort (comparator
sum up a con
subset of T, otherwise returns false S.issuperset (t) #如果s是t的超集, returns True, otherwise returns false S.union (T) #返回一个新集合, which is the set of S and T S.intersection ( T) #返回一个新集合, the set is the intersection of S and T #返回一个新集合 s.difference (t), which is a member of S but not a member of T, that is, the element s.symmetric_defference (T) that returns s that is different from T #返回所有s和t独有的 (
Non-shared element collection s.copy () #返回一个s的浅拷贝, efficiency is better than factory #方法 (for variabl
collections or containers usually we use arrays to hold some basic data types, arrays are types supported by compilers, but one obvious disadvantage of arrays is that they have fixed sizes, and in general, only when the program is running can we know the exact number to save. The Java class Library provides a fairly complete set of container frameworks (collections framework) to address this problem. The ba
Learn Python collections every dayLearn Python collections every day
Based on the built-in data types (dict, list, set, and tuple), the collections module provides several additional data types: ChainMap, Counter, deque, defaultdict, namedtuple, and OrderedDict.ChainMap
ChainMap is a new feature of python3. It is used to form multiple maps into a new unit (the o
Collections ModuleOn the basis of the built-in data type (DICT, list, set, tuple),The collections module also provides several additional data types: Counter, deque, Defaultdict, Namedtuple, and Ordereddict.1.namedtuple: Generate a tuple that can access the content of an element by using a name2.deque: Double-ended queue to quickly append and eject objects from the other side3.Counter: Counter, mainly used
Set Map, variable parameters, Collections, mapcollections
Features of Map setsJava. util. Map Features of the Map set:1. It is a double-row set. key and value values must be assigned at the same time when values are assigned.2. It is an unordered set (the order of elements stored and retrieved may be inconsistent)3. The key value cannot be repeated, and the value can be repeated.4. One key can only correspond to one vlaue5. When defining a set, you ca
C # Custom CollectionsFor the vast majority of game developers who are based on the Unity game engine to develop business-grade high-quality games, it is necessary to develop our "custom collections" using the C # language to develop technology applications such as "Object buffer pooling".According to the author's experience, a good C # "custom collection" needs to meet the following requirements:1: You can use foreach to iterate through the collectio
C # Custom CollectionsFor the vast majority of game developers who are based on the Unity game engine to develop business-grade high-quality games, it is necessary to develop our "custom collections" using the C # language to develop technology applications such as "Object buffer pooling".According to the author's experience, a good C # "custom collection" needs to meet the following requirements:1: You can use foreach to iterate through the collectio
There are many collections in Java: List,arraylist,vector,hashsettreeset, the differences between them, the framework of the Java collection, and so on are always vague, saying there is time to summarize.One, collection interface and iterator interface1.Collection Frame:The collection interface mainly defines some methods for manipulating the set elements:
boolean
Add ( Ee)Ensures that this collection contains the specified element
the order of each added element, which can be repeated, justListthe length of the variable;MapThe collection is also like a sugar jar, but each of her data is made up of two values. If you accessListthe elements in the collection can be accessed directly based on the index of the element, if access is requiredMapthe elements in the collection, which can be based on each element'sKeyvisit and ask thevalue; If you accessSetThe elements in the collection can only be accessed based on the element i
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.