I have an array of positive/negative ints
int[] numbers = new int[10];
numbers[0] = 100;
numbers[1] = -34200;
numbers[2] = 3040;
numbers[3] = 400433;
numbers
In Java 8:
List list = Arrays.stream(numbers).boxed().collect(Collectors.toList());
int n = 490;
int c = list.stream()
.min(Comparator.comparingInt(i -> Math.abs(i - n)))
.orElseThrow(() -> new NoSuchElementException("No value present"));
Initially, you can use a List instead of an Array (lists have much more functionality).