Let us say I have a list of points returned with a sort function:
List<Point> points = new ArrayList<>(); points.add(new Point(3, 30)); points.add(new Point(1, 10)); points.add(new Point(2, 20)); points.stream() .sorted((p1, p2)->p1.x.compareTo(p2.x)) .forEach(System.out::println); How do I make sorted(...) conditional based on a boolean flag (sortThePoints), something like the below
points.stream() if(sortThePoints){ .sorted((p1, p2)->p1.x.compareTo(p2.x)) } .forEach(System.out::println);
if(sortThePoints) Collections.sort(points, (p1, p2)->p1.x.compareTo(p2.x))sortThePointsaffects the collection elements?? If yes then usefilter();