list
Go language implements mutex lock, random number, time, List
Go language implements mutex lock, random number, time, List import ( “container/list” “fmt” “math/rand” //Remark 2: Random number package “sync” //Remark 1: Package of asynchronous tasks “time” ) type INFO struct { lock sync.Mutex //Remark 1: Asynchronous lock Name string Time int64 } var List *list.List = list.New() //Note 3: Initialize List variable func main() { var Info INFO go func() { for i := 0; i <5; i++ { time.Sleep(time.Duration(1e9 * int64(rand.Intn(5))))//Remark 2: Random number rand.Intn(5) 1e9 is scientific notation, 1 * 10 is 9 second power Info.lock.Lock()//Remark 1: Lock Info.Name = fmt.Sprint(“Name”, i) //Remarks: Sprint formats its parameters in the default format, concatenates all outputs to generate and returns a string. If two adjacent arguments are not strings, a space will be added between their outputs Info.Time = time.Now().Unix() + 3 Info.lock.Unlock()//Remark 1: Unlock List.PushBack(Info)//Remark 3: List expression call } }() goGetgoods() select {} } func Getgoods() { for { time.Sleep(1e8) for List.Len() > 0 {//Remark 3: Use of List object N, T := List.Remove(List.Front()).(INFO).name() //Note 3: The use of List objects and the wonderful use of value.(type) now := time.Now().Unix() //Note 4: Get the converted timestamp of the current date if T-now <= 0 { fmt.Println(N, T,…
Django other (site, list, upload
1.Static files: The CSS, images, and js in the project are all static files Static files are generally placed in a separate directory to facilitate management When calling in an html page, you also need to specify the path of the static file. Django provides a parsing method to configure the static file path Static files can be placed in the project root directory or in the application directory. Since some static files are common in projects, it is recommended to place them in the project root directory for easy management 1.Define the static file search path in the project/settings.py file STATIC_URL =’/static/’STATICFILES_DIRS = [ os.path.join(BASE_DIR,’static’),] 2.Create a static directory in the project root directory, and then create img and css , js directory 3.Define the view jingtai in the application name booktest/views.py defjingtai(request): returnrender(request,’booktest/jingtai.html’) 4.Configure url in booktest/urls.py url(r’^jingtai/$’,views.jingtai), 5.Create jingtai.html file under templates/booktest/ Dynamic configuration:{%load static from staticfiles%} 1.Question 1:djangoHow to determine the current request for a static file? http://127.0.0.1:8000/static/images/bjt.png Answer: Request path/static/images/ bjt.pngThe beginning of /static/ withsettings.py中STATIC_URLCompare, if they are the same, they are considered static files 2.Question 2: In which directory on the disk are static files found? Answer: The remaining path after judgmentimages/ bjt.png Option…
UML demonstration of Java serialization 82Set, Collection, List, and Map
1. UML Demonstration Collection Collection Collection Inheritance Structure Diagram 2. Set collection 1. Characteristics of List storage elements: ordered and repeatable. In order, what is the order in which they are stored and what order they are taken out. 2. Characteristics of Set storage elements: unordered and non-repeatable. When they are stored in the same order, when they are taken out, they may not be in the original order. 3.SortedSet features Characteristics of storing elements: Unordered and non-repeatable, but the stored elements can be automatically sorted according to the size of the elements. 3. Introduction to the underlying data structure of commonly used collection classes 1. The bottom layer of ArrayList uses an array to store elements, so the ArrayList collection is suitable for querying, but not suitable for frequent random additions and deletions of elements. 2. The bottom layer of LinkedList uses a two-way linked list. This data structure stores data. Linked lists are suitable for frequent additions and deletions of elements, but are not suitable for query operations. 3. The bottom layer of Vector is the same as the ArrrayList collection, but Vector is thread-safe and less efficient, so it is rarely used now. 4. Map collection inheritance…
[Reprint] Detailed explanation of the relationship between ArrayList, List, LinkedList, and Collection in java
Reprint link: http://www.cnblogs.com/liqiu/p/3302607.html Detailed explanation of the relationship between ArrayList, List, LinkedList, and Collection in java 1. Basic introduction (Set, List, Map) Set (set): The elements in the set are not ordered in a particular way, and there are no duplicate objects. Some of its implementation classes can sort objects in a collection in a specific way. List (list): The elements in the collection are sorted by index position. There can be duplicate objects, allowing objects to be retrieved according to their index position in the collection. Map (mapping): Each element in the collection contains a pair of key objects and value objects. There are no duplicate key objects in the collection, and the value objects can be repeated. Some of its implementation classes can sort key objects in a collection. 2. Basic interfaces and types 1. Iterator interface This interface allows traversing all elements in the collection. There are three methods: public boolean hasNext(): Determine whether there is a next element. public Object next(): Get the next element. Note that the return value is Object and may require type conversion. If there are no more elements available, a NoSuchElementException is thrown. Before using this method, you must first use…
JAVA07Object class, Date class, Calendar class, System class, packaging class, Collection, generics, List, Set, data structure, Collections
1. Overview java.lang.Object class is in the java language The following class is the parent class of all classes. The other class Object is the root class of the class hierarchy. Each class uses Object as its superclass. All objects (including arrays) implement the methods of this class. It contains 11 methods. 1 package cn.itcast.demo01.demo01; 2 3 public class Demo01ToString { 4 public static void main(String[] args) { 5 //The Person class inherits the Object class by default, and you can use the toString method 6 //Create Person object 7 Person person = new Person(“张三”,19); 8 String s = person.toString(); 9 // Directly printing the name of the object is actually calling the toStirng method of the object person = person.toString 10 System.out.println(s);//cn.itcast.demo01.demo01.Person@75412c2f 11 System.out.println(person);//cn.itcast.demo01.demo01.Person@75412c2f 12 } 13 } 14 15 1 package cn.itcast.demo01.demo01; 2 3 public class Person { 4 private String name; //Private member variables 5 private int age;// Private member variable 6 //Add the corresponding construction method 7 8 9 public Person() { 10 } 11 // Directly printing the address value of the object is meaningless, you need to override the toString method 12 13 14 @Override 15 public String toString() { 16 // Return super.toString()…
Implementation of placing arrays in java configuration files_@ConfigurationProperties binding configuration information to Array, List, Map, and Bean…
Related instructions: In SpringBoot,We can obtain and bind the information in the configuration file in the following ways: @Value annotation. Use Environment. @ConfigurationProperties annotation. By implementing the ApplicationListener interface ,registering the listener, for hard-coded acquisition, please refer to:https://www.jb51.net/article/187407. htm Hard coded loading file acquisition. …… Note : Under normal circumstances, the first and second methods are enough; but if you want to get them directly from the configuration file As for arrays, lists, maps, and objects, the support for the first and second types is not very good. Currently, only arrays, lists, and maps are available. As for beans, I’m a little helpless. At this time we can use the third method to obtain. Environment Description:Windows10, IntelliJ IDEA, SpringBoot 2.1.5.RELEASE @ConfigurationProperties annotation to obtain configuration information and bind to the object example: ; Preparation work:Introducing spring-boot-configuration-processor dependency Give me my complete pom.xml file: xsi:schemaLocation=”http: //maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.5.RELEASE com.aspire.yaml-properties yaml-properties 0.0.1-SNAPSHOT Yaml file and properties file syntax examples yaml file and properties file syntax examples 1.8 org.springframework.boot spring-boot-starter org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-configuration-processor org.springframework.boot spring-boot-maven-plugin Load demo. The information in the properties file is bound to the bean, and injected into the container example: Project…
[redis, 1] Java operates redis: string, list, map, custom objects
1. Operation of string, list, map objects 1. Introduction of jar: jedis-2.1.0.jar 2. Code/** * @param args */ public static void main(String[] args ) { //Connect to the redis service Jedis jedis = new Jedis(192.168.88.15,6379); //Password verification – if you do not set a redis password, you can use it without verification 1. Manipulate string, list, and map objects 1. Import jar: jedis-2.1.0.jar 2. Code /** * @param args */ public static void main(String[] args) { //Connect to redis service Jedis jedis = new Jedis(“192.168.88.15”,6379); //Password verification-if you have not set a redis password, you can use the relevant commands without verification. // jedis.auth(“abcdefg”); //Simple key-value storage jedis.set(“redis”, “myredis”); System.out.println(jedis.get(“redis”)); //Add on the basis of the original key. If the key does not exist before, import the key. //Redis has been set to correspond to “myredis” before. Executing this sentence will cause redis to correspond to “myredisyourredis” jedis.append(“redis”, “yourredis”); jedis.append(“content”, “rabbit”); //mset is to set multiple key-value值 parameters (key1, value1, key2, value2,…, keyn, valuen) //mget is to obtain the value corresponding to multiple keys. Parameters (key1, key2, key3,…, keyn) return a list jedis.mset(“name1″,”yangw”,”name2″,”demon”,”name3″,”elena”); System.out.println(jedis.mget(“name1″,”name2″,”name3”)); //map Map user = new HashMap(); user.put(“name”, “cd”); user.put(“password”, “123456”); //map stored in redis jedis.hmset(“user”, user);…
Summary of the relationship between Collection, List, Set, and Map in Java
As a newbie to Java, individual contacts are a bit confusing, so I’ll summarize their relationship 1. Relationship Collection –List: stored in a specific order –ArrayList, LinkList, Vector –Set: cannot contain duplicate elements –HashSet, TreeSet Map –HashMap, HashTable, TreeMap 2. Explain separately Collection: Collection is a parent interface. List and Set are sub-interfaces inherited from it. Collection is the most basic collection interface. The Java SDK does not provide classes that directly inherit from Collection, but provides sub-interfaces that inherit from him. Classes, such as List and Set. All Collection classes used support an Iterator() method to traverse. List: The List interface is ordered and will accurately insert elements into the specified position. Unlike the Set interface below, the List interface allows the same elements ArrayList: implements a variable-sized array, allowing all elements to be synchronized, that is, there is no synchronization method LinkList: allows null elements, usually operates at the head or tail, so it is often used for stacks, queues and deques Vector: similar to ArrayList, but Vector is synchronized, and Stack inherits from Vector Set: is a Collection interface that does not contain repeated elements HashSet: cannot have duplicate elements, the bottom layer is implemented using HashMap…
Traversal methods of Java collections Set, List, and Map
The examples in this article describe the traversal methods of Java collections Set, List, and Map, and share them with you for your reference. The specific methods are as follows: package com.shellway.javase; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import org.junit.Test; public class TestCollection { public static void print(Collection c){ Iterator it = c.iterator(); while (it.hasNext()) { Object object = (Object) it.next(); System.out.println(object); } } @Test public void demo1(){ Set set = new HashSet(); set.add(“AAA”); set.add(“BBB”); set.add(“CCC”); print(set); //The first traversal method of Set: using Iterator Iterator it1 = set.iterator(); for (String ss : set) { System.out.println(ss); } //The first traversal method of Set: using foreach for (String sss : set) { System.out.println(sss); } List list = new ArrayList(); list.add(“DDDDD”); list.add(“EEEEE”); list.add(“FFFFF”); print(list); //The first traversal method of List: because the list has order, use the size() and get() methods to obtain for (int i = 0; i <list.size(); i++) { System.out.println(list.get(i)); } //The second way to traverse List: using Iterator Iterator it = list.iterator(); while (it.hasNext()) { System.out.println(it.next()); } //The third way to traverse List: using foreach for (String s2 : list) { System.out.println(s2); } Map map = new TreeMap();…
Dark Horse Programmer – Java Basic Collection (1) Collection, set, list
——Java training, Android training, iOS training, .Net training, looking forward to communicating with you! —— /strong> There are many collections in Java, also called containers. The following figure shows the composition and classification of the collection framework. 1. Why do collection classes appear? Object-oriented languages embody things in the form of objects, so in order to facilitate the operation of multiple objects, objects are stored. Collections are the most commonly used way to store objects. 2. Arrays and collections are both containers. What are the differences? Although arrays can also store objects, their length is fixed; collection lengths are variable. Basic data types can be stored in arrays, while collections can only store objects. 3. Characteristics of collection classes Collections are only used to store objects. The length of the collection is variable, and the collection can store different types of objects. Collection Collection is a common interface in the collection framework. There are two sub-interfaces under it: List and Set. Affiliation: Collection |–List//Elements are ordered and elements can be repeated. Because the collection system has indexes. |–Set//The elements are unordered and the elements cannot be repeated. The following is an overview of Collection: 1 import java.util.*; 2…