当前位置:网站首页>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
边栏推荐
- Treatment of tensorflow sequelae - simple example record torch utils. data. dataset. Picture dimension problem when rewriting dataset
- Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
- Pytorch notes - complete code for linear regression & manual or automatic calculation of gradient code comparison
- Write your own redistemplate
- 自動控制(韓敏版)
- 你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
- lambda expressions
- Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
- Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
- 编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
猜你喜欢
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
container
去噪论文阅读——[CVPR2022]Blind2Unblind: Self-Supervised Image Denoising with Visible Blind Spots
sklearn之 Gaussian Processes
SQL injection
Configure domestic image accelerator for yarn
解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets
Practical operation - Nacos installation and configuration
Pytorch学习记录(七):处理数据和训练模型的技巧
Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
随机推荐
Algèbre linéaire chapitre 2 - matrice et son fonctionnement
在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
MySQL basic madness theory
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
SQL injection
数字图像处理基础(冈萨雷斯)一
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
The user name and password of users in the domain accessing the samba server outside the domain are wrong
Complete example demonstration of creating table to page - joint table query
Pytorch学习记录(九):Pytorch中卷积神经网络
金蝶EAS“总账”系统召唤“反过账”按钮
Linear algebra Chapter 2 - matrices and their operations
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
Pytorch learning record (XII): learning rate attenuation + regularization
Implementation of displaying database pictures to browser tables based on thymeleaf
Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
A general U-shaped transformer for image restoration
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising