0

I'm writing an application which will process a large amount of data and I need an ArrayList<Integer> functionality. I want to rewrite ArrayList class in order to work with an int type, instead of an Integer class. How much will this improve performance?

Ekz
  • 71
  • 7
  • It will do improve since no GC only native. – Volodymyr Lykhonis Aug 17 '13 at 15:12
  • 1
    No idea but you could probably rewrite the class fairly quickly and test it. (Most likely just a couple of search and replaces and remove the generics) – FDinoff Aug 17 '13 at 15:13
  • 1
    It entirely depends on *how* you use the `ArrayList`. Also, there are already implementations for "primitive" collections, such as fastutil. – mikołak Aug 17 '13 at 15:13
  • possible duplicate of [Integer auto-unboxing and auto-boxing gives performance issues?](http://stackoverflow.com/questions/6037389/integer-auto-unboxing-and-auto-boxing-gives-performance-issues) – SJuan76 Aug 17 '13 at 15:13
  • Please do a minimal effort before posting. Just googling "java autoboxing performance" gives you lots of information. – SJuan76 Aug 17 '13 at 15:14
  • see this for a stopwatch class which can be used to find which class is faster http://stackoverflow.com/questions/8255738/is-there-a-stopwatch-in-java (note:stopwatch is not 100% accurate) – bhathiya-perera Aug 17 '13 at 15:15

3 Answers3

4

Don't reinvent the wheel.

It was done long time ago :)

http://trove4j.sourceforge.net/javadocs/gnu/trove/list/array/TIntArrayList.html

it works great.

benchmarks

dantuch
  • 9,123
  • 6
  • 45
  • 68
  • No problem, I'm using Trove myself for the same reason - big amount of data that's needs to be stored in memory. – dantuch Aug 17 '13 at 15:30
0
ArrayList<int[]> arlist=new ArrayList<int[]>();
int ar1[]={1,2,3};
arlist.add(0,ar1);

Isnt this plausible?

Jebathon
  • 4,310
  • 14
  • 57
  • 108
0

You don't need to do this. See @dantuch's Answer.

I just want to point out the problems with using a specialized "list of int" class.

  • The class cannot be API compatible with the standard collection classes and interfaces. If you are trying to use some other API that requires a Collection or a List, then the specialized class cannot be used with it.

  • You won't be able to use polymorphism across the various "list of primitive" types.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216