[Python] collections module

The collections module in Python contains some container data types. import collections [x for x in dir(collections) if not x.startswith(‘_’)] # result: [‘ChainMap’, ‘Counter’, ‘OrderedDict’, ‘UserDict’, ‘UserList’, ‘UserString’, ‘abc’, ‘defaultdict’, ‘deque’, ‘namedtuple’] 1. collections.ChainMap() [Search multiple dictionaries] Search multiple dictionaries in the order in which they appear. m=collections.ChainMap(Dictionary 1, Dictionary 2, Dictionary 3,…): manages multiple […]

final finally finalize difference stream stream Stream method mvc aop ioc understanding the difference between Collection and Collections Nacos AP, CP

Method to create thread 1. The class inherits Thread and overrides the run() method 2. The class implements the Runnable interface and overrides the run() method (no return value, no exception will be thrown) 3. Implement the Callable interface and implement the call() method (with a return value and an exception will be thrown) To […]

New features of JDK: Stream (API for operating collections and arrays)

1. Stream Case:4 public static void main(String[] args) { List<String> citiesl =new ArrayList<>(); Collections.addAll(citiesl,”Nanjing City”,”Yangzhou City”,”Nanyang City”,”Changzhou City”); System.out.println(citiesl);//[Nanjing City, Yangzhou City, Nanyang City, Changzhou City] //Method 1: Original method List<String> citiesls =new ArrayList<>(); for (String s : citiesl) { if (s.startsWith(“南”)){ citiesls.add(s); } } System.out.println(citiesls);//[Nanjing City, Nanyang City] //Method 2: Stream stream List<String>ciiesl2=citiesl.stream().filter(c->c.startsWith(“南”)).collect(Collectors.toList()); System.out.println(ciiesl2); […]

Spring annotation magic: the perfect solution for uniqueness verification of object properties in collections

Spring Boot provides a powerful validation framework, but sometimes we need to create custom validation rules according to our own business needs. This article will introduce how to use Spring Boot custom annotations, validators, and reflection to check whether the value of a certain attribute of each object in the collection is unique. 1. Custom […]

Apache Commons Collections

Apache Commons Collections is an extension to java.util.Collection. Currently, the Collections package has two commons-collections and commons-collections4. The latest version of commons-collections is 3.2.2, which does not support generics and is no longer officially maintained. The latest version of collections4 is 4.4, and the minimum requirement is Java 8 or above. Compared with collections, it […]

mybatis custom type controller (TypeHandler) processes strings as collections

1. Question: Assume such a scenario The value in localurl is roughly like this: dwad21.jpg, dwad22.jpg, dwad.23.jpg is a string If I have a field (local_url) in the sql table that is the concatenation value of multiple url strings of local image resources. I want to get value plus value without extra conversion in java […]

Solving AttributeError: collections.defaultdict object has no attribute iteritems

Table of Contents Solving AttributeError: ‘collections.defaultdict’ object has no attribute ‘iteritems’ Problem Description wrong reason solution in conclusion Solving AttributeError: ‘collections.defaultdict’ object has no attribute ‘iteritems’ collections.defaultdict object iteritems method Resolve AttributeError: ‘collections.defaultdict’ object has no attribute ‘iteritems’ When programming in Python, sometimes we encounter errors similar to ??AttributeError: ‘collections.defaultdict’ object has no attribute ‘iteritems’??. […]

Containers (collections) in java, underlying principles of HashMap, differences between ArrayList, LinkedList, and Vector, reasons for hashMap loading factor 0.75

1. Containers in java Collections are mainly divided into two major interfaces: Collection and Map; the sub-interfaces of Collection include List and Set; the implementation classes of List collection include ArrayList, whose bottom layer is an array, and the bottom layer of LinkedList, which is a bidirectional acyclic list and Vector; the implementation classes of […]