java – 使用Tuple(double,int,int)的arraylist比两个arraylists
发布时间:2020-12-15 08:42:25 所属栏目:Java 来源:网络整理
导读:使用Tuple(double,int,int)的arraylist比三个单独的arraylists慢吗?我想避免创建大量的Tuple对象,但方法2是否通过自动装箱创建对象? //Method 1ArraylistTuple arr=new ArraylistTuple();Tuple t=new Tuple(double,int);class Tuple{ private double value
使用Tuple(double,int,int)的arraylist比三个单独的arraylists慢吗?我想避免创建大量的Tuple对象,但方法2是否通过自动装箱创建对象?
//Method 1 Arraylist<Tuple> arr=new Arraylist<Tuple>(); Tuple t=new Tuple(double,int); class Tuple{ private double value; private int a; private int b; } //Method 2 Arraylist<Double> arr=new Arraylist<Double>(); Arraylist<Integer> arr=new Arraylist<Integer>(); Arraylist<Integer> arr=new Arraylist<Integer>(); 解决方法
你的问题是缺少背景.这个问题已被多次询问,并没有单一的最佳解决方案.
在我看来,对数据建模的最佳方法是使用表示数据的逻辑类型. (您当前正在使用元组,但最好是使用方法使用特定类型.) 所以,我会做以下事情: List<NumberContainer> list = new ArrayList<NumberContainer>(); 特别是速度 – 这取决于你将如何使用数据.如果您正在寻找快速访问时间,最好使用地图并在某个值上键入每个项目. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |