How to convert Array to List

Plain Java public void givenUsingCoreJava_whenArrayConvertedToList_thenCorrect() { Integer[] sourceArray = { 0, 1, 2, 3, 4, 5 }; List<Integer> targetList = Arrays.asList(sourceArray); } Commons Collection public void givenUsingCommonsCollections_whenArrayConvertedToList_thenCorrect() { Integer[] sourceArray = { 0, 1, 2, 3, 4, 5 }; List<Integer> targetList = new ArrayList<>(6); CollectionUtils.addAll(targetList, sourceArray); } Guava public void givenUsingGuava_whenListConvertedToArray_thenCorrect() { List<Integer> sourceList = …

Quick Sort

QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways. Always pick first element as pivot. Always pick last element as pivot (implemented below) Pick a random element as pivot. …

TreeMap in Java

Introduction The TreeMap in Java is used to implement Map interface and NavigableMap along with the AbstractMap Class. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used. This proves to be an efficient way of sorting and …