当前位置:网站首页>List segmentation best practices
List segmentation best practices
2022-04-23 06:08:00 【New ape and horse】
Catalog
One ListUtils.partition Method
3、 ... and Source code analysis
3.1 ListUtils.partition Source code analysis
3.2 Lists.partition Source code analysis
In our work, we often encounter the need to divide the array into multiple sub arrays , Then the demand for batch processing . Is there a more elegant implementation ?
After many times of practice , Sum up ListUtils.partition and Lists.partition Two better implementations . The two implementations are described below .
One ListUtils.partition Method
1.1 Introduce dependencies
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
1.2 Code demonstration
public static void main(String[] args) {
// Initialize array
List<Integer> parList = new ArrayList<>();
IntStream.range(0, 30).forEach(parList::add);
// Split into subarrays
List<List<Integer>> subList = ListUtils.partition(parList, 10);
// Traversal subarray
subList.forEach(list -> {
System.out.println(String.format("subList size:%s", list.size()));
System.out.println(String.format("list:%s", list.toString()));
});
}
1.3 Output results

Two Lists.partition Method
2.1 Introduce dependencies
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
2.2 Code demonstration
public static void main(String[] args) {
// Initialize array
List<Integer> parList = new ArrayList<>();
IntStream.range(0, 30).forEach(parList::add);
// Split into subarrays
List<List<Integer>> subList = Lists.partition(parList, 10);
// Traversal subarray
subList.forEach(list -> {
System.out.println(String.format("subList size:%s", list.size()));
System.out.println(String.format("list:%s", list.toString()));
});
}
2.3 Output results

3、 ... and Source code analysis
3.1 ListUtils.partition Source code analysis

Final ListUtils.partition call ListUtils.Partition Method to handle .
ListUtils.Partition Source code is as follows :

Partition Class as ListUtils Static inner class inheritance AbstractList class . Rewrote get and size Method .
3.2 Lists.partition Source code analysis

Lists.partition The method will eventually be called new Partition<>(list, size).
Partition Class source code is as follows :

Partition Class as Lists Static inner class inheritance AbstractList class . Rewrote get 、 size、isEmpty Method .
Four Performance comparison
because Lists.partition and ListUtils.partition The underlying implementations are implemented through Partition Class to achieve , Similar performance .
版权声明
本文为[New ape and horse]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533487647.html
边栏推荐
- Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
- The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect
- Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
- A general U-shaped transformer for image restoration
- 如何利用对比学习做无监督——[CVPR22]Deraining&[ECCV20]Image Translation
- 编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
- JDBC tool class encapsulation
- Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
- MySQL basic madness theory
- How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation
猜你喜欢

Implementation of displaying database pictures to browser tables based on thymeleaf

Dva中在effects中获取state的值
![Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi](/img/1b/4eea05e2634780f45b44273d2764e3.png)
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi

深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索

Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox

SQL injection

JDBC connection database

Linear algebra Chapter 2 - matrices and their operations

The bottom implementation principle of thread - static agent mode

Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
随机推荐
Manually delete registered services on Eureka
Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
Pytorch学习记录(九):Pytorch中卷积神经网络
DBCP usage
Fact final variable and final variable
umi官网yarn create @umijs/umi-app 报错:文件名、目录名或卷标语法不正确
MySQL basic madness theory
Rsync for file server backup
给yarn配置国内镜像加速器
Algèbre linéaire chapitre 2 - matrice et son fonctionnement
JDBC operation transaction
Gaussian processes of sklearn
Pytoch learning record (x): data preprocessing + batch normalization (BN)
Pytoch -- data loading and processing
Pytorch学习记录(四):参数初始化
Create enterprise mailbox account command
图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
Software architecture design - software architecture style
Contrôle automatique (version Han min)
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.