0

could you explain the code which is used in checking given array is consecutive or not

Set<Integer> set = Arrays.stream(array).boxed() .collect(Collectors.toCollection(TreeSet::new));

6th Nov 2021, 4:46 PM
Ajay K Santhosh
Ajay K Santhosh - avatar
1 Antwort
+ 2
Arrays.stream() turns an array into a stream object; boxed() transforms/boxes the stream elements from int to Integer; collect.() takes a Collector object which in this case is supplied through the static method Collectors.toCollection() which itself takes a Supplier<Collection> which in this case is a TreeSet; the TreeSet is a binary search red and black tree which sorts the integers as they are inserted into the TreeSet in ascending order as Integer is an instanceof Comparable<Integer>; I don’t see where you check if the array is conecutive or not in this code
6th Nov 2021, 5:52 PM
Kamen Studentov
Kamen Studentov - avatar