Java is nominal, as in, it likes names of things.
You're fighting the language. Stop doing that. Go with the flow.
List<Integer>
could indeed be used to represent a point, but it's real shite at it. It doesn't print nicely, and it is trivial to make an 'invalid state' object - List.of()
, what coordinate is that? List.of(1, 2, 3)
, what's going on there?
Make a class that represents the idea of a 2D point.
public record Point(int x, int y) {}
will do that, for exmaple.
But, let's say you want to keep shooting yourself in the foot and abuse List<Integer>
as a coordinate pair, you do not want flatmap.
Given, say, the origin coordinate ((0, 0)
), as well as x=5 and y=10, then flatMap would let you obtain a stream that is just the sequence 0, 0, 5, 10
. This is not good - streams work by letting you inspect and operate on individual items. There's no way to check x * y
at that point.
So, you don't want flatmap. You'd just operate on your numbers.stream()
, which is a stream of List<Integer>
objects. You can then apply your logic to each of these objects, which are just a real bad way of representing 2D coordinates.
numbers.stream().anyMatch(list -> list.get(0) * list.get(1) < 0);