Java – ArrayLists using tuple (double, int, int) are slower than two ArrayLists

Is an ArrayList using tuple (double, int, int) slower than three separate ArrayLists? I want to avoid creating a large number of tuple objects, but does method 2 create objects through automatic boxing?

//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>();

Solution

Your problem is lack of background This problem has been asked many times and there is no single best solution

In my opinion, the best way to model data is to use logical types that represent data (you are currently using tuples, but it is best to use methods with specific types.)

Therefore, I will do the following:

List<NumberContainer> list = new ArrayList<NumberContainer>();

Speed in particular – it depends on how you will use the data If you are looking for quick access time, it is best to use a map and type each item on a value

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>