Lists.newArrayListWithExpectedSize( int estimatedSize)
Lists.newArrayListWithExpectedSize( int estimatedSize) 构造一个期望长度为estimatedSize的ArrayList实例。
源码:
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize) {
return new ArrayList(computeArrayListCapacity(estimatedSize));
}
//计算集合的容量
@VisibleForTesting
static int computeArrayListCapacity(int arraySize) {
//判断是否小于0,小于0则抛出异常。
CollectPreconditions.checkNonnegative(arraySize, "arraySize");
return Ints.saturatedCast(5L + (long)arraySize + (long)(arraySize / 10));
}
//检查是否小于0
@CanIgnoreReturnValue
static int checkNonnegative(int value, String name) {
if (value < 0) {
throw new IllegalArgumentException(name + " cannot be negative but was: " + value);
} else {
return value;
}
}
//判断计算出来的数组长度是否在int的范围内
public static int saturatedCast(long value) {
if (value > 2147483647L) {
return 2147483647;
} else {
return value < -2147483648L ? -2147483648 : (int)value;
}
}
Lists.newArrayListWithExpectedSize( int estimatedSize)的更多相关文章
- Lists
List类主要提供了对List类的子类构造以及操作的静态方法.在类中支持构造ArrayList.LinkedList以及newCopyOnWriteArrayList对象的方法.其中提供了以下构造Ar ...
- [置顶] Guava学习之Lists
Lists类主要提供了对List类的子类构造以及操作的静态方法.在Lists类中支持构造ArrayList.LinkedList以及newCopyOnWriteArrayList对象的方法.其中提供了 ...
- guava学习--集合1
Lists: 其内部使用了静态工厂方法代替构造器,提供了许多用于List子类构造和操作的静态方法,我们简单的依次进行说明,如下: newArrayList():构造一个可变的.空的ArrayList实 ...
- Guava集合工具
JDK提供了一系列集合类,如下所示,极大的方便了开发工作,并针对这些类提供了一个工具类java.util.Collections,Guava在此基础上添加了一些常用工具类方法,相比于java.util ...
- java代码之美(9)---guava之Lists、Maps
guava之Lists.Maps 谷歌提供了guava包里面有很多的工具类,Lists和Maps集合工具,集合操作做了些优化提升. 1.概述 1.静态工厂方法 (1)Guava提供了能够推断范型的静态 ...
- java代码(9) ---guava之Lists、Maps
guava之Lists.Maps 谷歌提供了guava包里面有很多的工具类,Lists和Maps集合工具,集合操作做了些优化提升 一.概述 1.静态工厂方法 (1)Guava提供了能够推断泛型的静态 ...
- [LeetCode] Merge k Sorted Lists 合并k个有序链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这 ...
- [leetcode 23]Merge k Sorted Lists
1 题目 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexi ...
- LeetCode——Merge k Sorted Lists
Discription: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its ...
随机推荐
- 艺术模板 art-template-web
艺术模板 art-template____jQuery 项目可用 最快的模板渲染引擎 兼容 ejs 语法 推荐语法 {{each arr}} {{$value}} ---- {{$index}} {{ ...
- vue-router 之 keep-alive
参考 https://www.jianshu.com/p/0b0222954483
- 太原面经分享:如何用js实现返回斐波那契数列的第n个值的函数
面试攒经验,let's go! 值此高考来临之际,闲不住的我又双叒叕出发去面试攒经验了,去了公司交待一番流程后,面试官甩给了我一张A4纸,上面写着一道js算法笔试题(一开始我并不知道这是在考察js算法 ...
- .node 文件require时候显示Error: The specified module could not be found
参考文章:https://stackoverflow.com/questions/41253450/error-the-specified-module-could-not-be-found 第一:你 ...
- 输入正整数n,求各位数字和
import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/5 10:24 * @description ...
- socket(套接字)初使用
socket层 socket:是应用层与TCP/IP协议通信的中间软件抽象层,是一组接口,在设计模式中,socket其实就是一个门面模式,它把复杂的TCP/IP协议隐藏在socket接口后面. 基于T ...
- CentOS / RHEL 7 : How to setup yum repository using locally mounted DVD
1. Mount the RHEL 7 installation media ISO to some directory. For example /mnt : # mount -o loop rhe ...
- esyui datagrid 水平方向下方出来滚动条的原因是因为使用了同一列名
esyui datagrid 水平方向下方出来滚动条的原因是因为使用了同一列名
- XP下ubuntu双系统安装方法
利用u盘将iso刻录 从u盘启动 连续按alt+f2 进入ubuntu试用 打开终端 输入 sudo umount -l /cdrom sudo umount -l /isodevice 然后安装un ...
- Windows nessus安装
1.官网下载nessus,下载速度很慢,要有耐心 2.安装,安装完成后访问https://localhost:8834,最好使用chrome浏览器 3.页面注册,更新plugins等 4.如果页面无法 ...