java8转换数组。找到最接近指定数据

List lsstr=Arrays.asList(arear);//数组转list

List listWithoutNulls = lsstr.stream().filter(Objects::nonNull)//list去掉空值

.collect(Collectors.toList());

String[] toBeStored = new String[listWithoutNulls.size()];//list转数组

listWithoutNulls.toArray(toBeStored);

double[] doubles = Arrays.stream(toBeStored).mapToDouble(Double::valueOf).toArray();//字符串数组转doubel数组

//从数组中找到近似值

List list = Arrays.stream(numbers).boxed().collect(Collectors.toList());

double c = list.stream()

.min(Comparator.comparingDouble(i -> Math.abs(i - num)))

.orElseThrow(() -> new NoSuchElementException("No value present"));

你可能感兴趣的:(java后台,开发,java)