File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Use of  Arrays of Wrapper Data Types. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Use of  Arrays of Wrapper Data Types." Watch "Use of  Arrays of Wrapper Data Types." New topic
Author

Use of Arrays of Wrapper Data Types.

Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 277


Hi all

Somewhere in the project i am working on, i see the usage of Integer Arrays .
In this case length od array is fixed because we know the size has to be same and we are not using collections like List<Integer> .
framework used is Spring ,SWF ,JSP with DB2.
We have that design and DAO layer and service layer and POJOs.
Somehow i have this doubt(may be i read somewhere) to use collections as much as possible.
and not Integer arrays but since size is also fized(constant arrays) we use this and knowing using core api is always better.

Which one is performance-effective.?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3047
    
    1

Stop worrying about performance and start worrying about code readability. List<Integer> is much more clear than Integer[].

On top of that, List<Integer> is much more flexible as well. What is your reason to prefer arrays over collections?
Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 277
Only reason for using wrapper arrays over collection -

fixed size of array and little better performance since using collections could be slower than using Integer[]
but yes Integer[] does look ugly and i intend to change it.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

Almost always, clarity and maintainability of the code is much more important than micro-optimizations.

You should especially not "optimize" code purely based on your intuition that something is faster than something else (for example "my intuition tells me that arrays are faster than collections"). Your intuition is often wrong, or the performance difference is so small that it does not matter at all - the cost of making your code ugly but "fast" most often outweighs the benefits of making the code clear and easy to maintain.

Only optimize if you've measured that there is an actual performance problem, and optimize only based on actual evidence (measurements, for example with a profiler). Optimizing code that only your intuition tells you needs optimizing often means that you're wasting your time.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Use of Arrays of Wrapper Data Types.
 
Similar Threads
Array vs Collection
ArrayList Vector Collections Array
Sorting elements by associated integers.
An object to hold several arrays
Help with Arrays