What is a non-primitive data structure

Java blog for programmers

Any data structure of the Collection API, even if used generically, only accepts objects. Primitive data types do not accept the collections, which means that wrapper objects are necessary (Java 5 inserts seemingly primitive elements via boxing, but in reality they are wrapper objects). Even if it means:

List list = new ArrayList ();

list.add ( 1.1 );

list.add ( 2.2 );

there are two new double objects that are created and move into the list. Written differently and more clearly what really happens:

List list = new ArrayList ();

list.add (Double.valueOf (1.1) );

list.add (new Double (2.2) );

The new operator cannot be read from Double.valueOf (), but the method is implemented as: Double valueOf (double d) {return new double (d); }.

Special libraries

For high-performance applications and a large number of primitive elements, it makes sense to use a class for the special data type. Instead of programming something like this yourself, the developer can fall back on three implementations:

  • fastutil (http://fastutil.dsi.unimi.it/). Extension by data structures for (very many) primitive elements and high-performance input / output classes.
  • GNU Trove (http://trove.starlight-systems.com/). Stable and development is active. However, new data structures from Java 5 or 6 such as queues are not included.
  • Apache Commons Primitives (http://jakarta.apache.org/commons/primitives/). Version 1.0 is stable, but has not been updated since the end of 2003.
  • similar posts

    Posted in General