in JavaScript Technology

Java ArrayList of Doubles

What is DoubleArrayList?

A type-specific array-based list; provides some additional methods that use polymorphism to avoid (un)boxing.

This class implements a lightweight, fast, open, optimized, reuse-oriented version of array-based lists. Instances of this class represent a list with an array that is enlarged as needed when new entries are created (by increasing its current length by 50%), but is never made smaller (even on a clear()). A family of trimming methods lets you control the size of the backing array; this is particularly useful if you reuse instances of this class. Range checks are equivalent to those of java.util‘s classes, but they are delayed as much as possible. The backing array is exposed by the elements() method.

This class implements the bulk methods removeElements(), addElements() and getElements() using high-performance system calls (e.g., System.arraycopy()) instead of expensive loops.

Method

double[]toDoubleArray(List stringArray)
to Double Array if (stringArray == null) { return null; double[] result = new double[stringArray.size()]; for (int i = 0; i < stringArray.size(); i++) { try { if (stringArray.get(i) != null) { result[i] = Double.parseDouble(stringArray.get(i)); …
double[]toDoubleArray(List values)
to Double Array double[] ds = new double[values.size()]; for (int i = 0; i < ds.length; i++) { ds[i] = Double.parseDouble(values.get(i)); return ds;
ListtoDoubleList(double[] array)
to Double List List<Double> result = new ArrayList<Double>(array.length); for (int i = 0; i < array.length; i++) { result.add(i, array[i]); return result;
ListtoDoubleList(double[] array)
to Double List List<Double> list = new ArrayList<Double>(array.length); for (double el : array) list.add(el); return list;
ListtoDoubleList(double[] doubleArray)
Convert the given double array to a double list List<Double> doubleList = new ArrayList<Double>(doubleArray.length); for (double currDouble : doubleArray) { doubleList.add(currDouble); return doubleList;
ListtoDoubleList(Double[] in)
to Double List List<Double> ret = new ArrayList<Double>(); for (Double d : in) ret.add(d); return ret;
ListtoDoubleList(final E[] array)
to Double List List<Double> doubleList = null; if (array != null) { doubleList = new ArrayList<Double>(array.length); for (E e : array) { if (e != null) { try { doubleList.add(Double.parseDouble(e.toString())); } catch (NumberFormatException nfe) { …
ListtoDoubleList(List values)
to Double List return values;
ListtoDoubleList(List list)
Converts a list of integers to a list of doubles. List<Double> doubleList = new ArrayList<Double>(); for (Integer val : list) { doubleList.add(val.doubleValue()); return doubleList;
ListtoDoubleList(String[] array)
Converts a String array to a double array. List<Double> out = new ArrayList<Double>(array.length); for (int i = 0; i < array.length; i++) { if (array[i] == null) throw new RuntimeException(“Null value in position ” + i); out.add(Double.parseDouble(array[i])); return out;

Define an ArrayList with the double

Here is how to define an ArrayList with the double

List<Double> list = Arrays.asList(1.38, 2.56, 4.3);

In order to pass this result to the ArrayList constructor use the following code:

List<Double> list = new ArrayList<>(Arrays.asList(1.38, 2.56, 4.3));

Learn Java – top recommended books