I'm working on finding the big O for my code and I have been using a lot of Java streams to solve my problems. I was wondering how I can figure out the complexity of this code.
I'm not 100% sure, but I think that .filter and .limit has a complexity of O(1) and .sorted and .collected has a complexity of O(n).
return robots.stream() // start streaming the values in the list
.filter(robot -> !robot.isBusy()) // only keep the robots that aren't busy
.sorted(Comparator.comparingDouble(robot -> robot.getLocation().dist(location))) // sort by distance to job location
.limit(needed) // max out at the needed robots for the job
.collect(Collectors.toList()); // put the values into a list
}