Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.29 KB

File metadata and controls

39 lines (30 loc) · 1.29 KB

ArrayUtils

Contents

toArray

ArrayUtils has the ability to dynamically determine the type of your list.

List<Comparable> comparables = new ArrayList<>();
comparables.add(null);
comparables.add(1);
comparables.add(3.1415);
comparables.add("Lars");
Comparable[] comparableArray = ArrayUtils.toArray(comparables);

snippet source | anchor

This works in almost all cases with the notable exceptions of empty arrays, some common interfaces which will not be preferenced. In which case you can always use the overloaded method

Comparable[] array = ArrayUtils.toArray(comparables, Comparable.class);

snippet source | anchor

Back to User Guide