Skip to content

Instantly share code, notes, and snippets.

@SiAust
Last active September 1, 2020 09:32
Show Gist options
  • Select an option

  • Save SiAust/91d8cafcb28f6c07c280d0d483ce1e7a to your computer and use it in GitHub Desktop.

Select an option

Save SiAust/91d8cafcb28f6c07c280d0d483ce1e7a to your computer and use it in GitHub Desktop.
Reverse list getter
Scanner sc = new Scanner(System.in);
List<Integer> numbers = Arrays.stream(sc.nextLine().split(" "))
.mapToInt(Integer::parseInt).boxed().collect(Collectors.toList());
int index = sc.nextInt();
if (index < 0) {
System.out.println(numbers.get(numbers.size() + index));
} else {
System.out.println(numbers.get(index));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment