1. DictionariesDo not agree with multiple values for a key: when there is a conflict (that is. Dictionary keys are assigned repeatedly), taking the last (recent) assignment.>>> dict1 = {' foo ': 789, ' foo ': ' XYZ '}>>> Dict1{' foo ': ' XYZ '}2. Sets are divided into mutable sets (set) and immutable sets (Frozenset)(1) Variable set (set). You can add and remove elements, and do not agree to immutable collections (Frozenset).Note that a mutable set (s
Collection:#一种数据类型, there is the function of the heavy, disorderly (can not be based on the subscript to take the value)Two methods of defining collections:1: First define a list and then convert to a collection by forcing the typea=[1,2,3,4,4,5] #set (a) force type to convert list A to a collection, a duplicate value of 4 is reset2:s={1,2,3,4} #与字典要区别开Operation of the collection:List1 = {1, 2, 3, 4, 5, 6, 9}List2 = {2, 3, 4, 6, 1}List3 = {1, 2, 3}Pri
first, comparable interface, collections classCommon Algorithms for list:
Sort (List); If you need to sort your custom classes, you have to implement the comparable interface to implement a method that compares two class sizes
Shuffle (List); Random arrangement
void reverse (List); Reverse order (linked efficiency)
Copy (); Copy the collection, provided the size () is the same (length, and the difference in capacity)
Fill (Lis
First, the collection(1) Assembly interfaceCollection-list-queue-setMap(2) Collections Tool classSecond, List(1) ArrayList default capacity is 10, 1.5 times times growth, thread unsafe(2) LinkedList bidirectional linked list implementation, thread insecure(3) Copyandwritearraylist thread safety, through the replication of data to achieve final synchronization, can not ensure simultaneous synchronization, high-performance read, write performance is low
open ('file_new','W') as FW:#This is a multi-file operation, open two files, FR is read FILE.TXT,FW is a new File_bak file forLineinchFr#each row in the loop file.txtNew_line = Line.replace ('I'm','Me') Fw.write (new_line)#write to the File_bak fileCollection:A collection is also a data type, a similar list of things, it is characterized by unordered, non-repeating, that is, the collection is no duplication of dataFunction of the collection:1, it can be a list of duplicate data remov
Today, look at the Java pen Test, found that there is such a problem, compare collection and collections differences. Keep a record of the differences here.1, Java.util.Collection is a collection interface . It provides a common interface method for basic manipulation of collection objects. The collection interface has many specific implementations in the Java class Library. The meaning of the collection interface is to provide a maximum unified opera
a linked list to extend the HashMap class, and he supports the ordering of entries in the mapping table. HashMap have no order, and linkedhashmap, elements can be sorted sequentially in the order in which they were inserted, or in the order they were last accessed, from the earliest to the latest.The TreeMap class is efficient when traversing a sorted key. Keys can be sorted by using the comparable interface or the comparator interfaceExample:Linkedhashmap if the order is sorted by access, then
1. Nesting of sets:The use of collections actually has a lot in common with the usage of arrays, which are nested in arrays when using an array of two-dimensional arrays;Is it possible to do so in a collection?Of course it is possible, for example, for the most complex map collection;MapThe A, genericsUsing angle brackets To specify the type of deposit, in short, a limit to the data deposited, and the group comparison, can only be stored in a data typ
Next , "Java Foundation--Set (a)--collection system and Collection"Four. Use of iteratorsSteps to use:1. Gets the iterator object through the collection object.2, through the iterator object judgment.3. Get through an iterator object.The principle of iteratorsBecause the data structure of various collections is different, the way of storage is different, so the way to take out is different.At this point, we define the function of judgment and acquisi
1, at the time of the Guide package can import its static part, so that in the class to use it, you can directly use its nameFor example: Map.entry access, after the class file header imports import Java.util.Map.Entry after simplification for entry.2. You can use the modifier to return a value type method name ( parameter type ...). formal parameter name ) {}" to pass in an indeterminate number at the same time, parameters of the same parameter type. For example, when the data of an int of an
1.java.util.collection is a collection interface . It provides a common interface method for basic manipulation of collection objects. The collection interface has many specific implementations in the Java class Library. The meaning of the collection interface is to provide a maximum unified operation for a variety of specific collections.2.java.util.collections is a wrapper class . It contains a variety of static polymorphic methods related to set op
list inherit from Collection, First of all, set:First,SetCollectionSet is an element that does not contain duplicate elements. Collection , a reference to the object is stored, and there are no duplicate objects: Set set=new HashSet (); String s1=new string ("Hello"); String s2=s1; String S3=new string ("word"); Set.add (S1); Set.add (S2); Set.add (S3); System.out.println (Set.size ());//The number of print collection objects is 2.//traversal set method:iteratorItoo are mainly in a one-to-m
Collections Class Summary ***************************There are three main types of Java collections:Set (set)List (lists)Map (map)Collection interfaceCollection is the most basic collection interface, declaring a common method that applies to a Java collection ( including set and list only).Both Set and list inherit the Conllection,map.Class collections is a wrapper class. It contains a variety of static po
Since the initial Java 2 platform, Version 1.2 has been released, the Java collections Framework has been evolving. In Java SE 5, the introduction of generics enhances the framework, and the introduction of java.util.concurrent adds direct support for concurrency (see Resources). In Java SE 6, a better bidirectional collection access feature is added to the framework. This article will introduce you to all of these aspects of the collection library an
Mainly divided into collection and map,collection. Gets the saved object reference using the index, which we can think of as an array-like class, while map stores the object as a key-value pair, and each object has a key value corresponding to it when it is stored in the map. Collection is the top-level interface of the collection class, and its directly inherited interfaces have set and list. Collections is a tool class/helper class for the collectio
, mainly consists of the following three ways:(1) whether Hasnext () has the next element.(2) Next () returns the next element.(3) Remove () deletes the current element.Iii. Introduction to several commonly used interfaces and classes in Java1.List InterfaceThe list is concerned with indexes, which are specific to the index, compared to other collections: Get (int index), add (int index,object o), indexOf (Object o). ArrayList can interpret it as a
, any two elements E1 and E2 have E1.equals (E2) =false,set have a maximum of one null element.Obviously, the constructor of a set has a constraint that the passed-in collection parameter cannot contain duplicate elements.Note: Variable objects (Mutable object) must be handled with care. If a mutable element in a set changes its state, causing Object.Equals (Object) =true will cause some problems.Map InterfaceNote that map does not inherit the collection interface, and map provides a key-to-valu
The role of collections in Python is: uniquenessThe collection is unordered and cannot be indexed to an element in the collectionTo create a collection:Set1 = {1,2,3,4,5}Set1 = Set ([1,2,3,4,5])A collection can quickly remove duplicate elements from a list:List1 = [1,2,3,4,5,5,3,1= List (set (List1))Output Result:>>>list1[1,2,3,4,5]To access the collection:You can use in or not in to determine whether an element is in the collection:inch Set1falseUse
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.