One idea
A lambda is a short function value. A stream is a clean way to process a collection step by step without writing manual loops for every task.
Where this fits
Your recruiter CLI will have candidate data in lists. You may need to show shortlisted candidates, count skills, sort by score, or print names in a clean format.
You can do all of that with normal for loops. Streams are useful when the job is a pipeline: filter, transform, sort, collect.
Candidate example
Assume your Candidate class has name, city, skills, and score getters. This code finds Java candidates in Bengaluru or remote-ready candidates, sorts by score, and prints a shortlist.
import java.util.Comparator;
import java.util.List;
public class ShortlistService {
public List<Candidate> shortlist(List<Candidate> candidates) {
return candidates.stream()
.filter(candidate -> candidate.getSkills().contains("Java"))
.filter(candidate -> candidate.getCity().equalsIgnoreCase("Bengaluru")
|| candidate.isRemoteReady())
.filter(candidate -> candidate.getScore() >= 70)
.sorted(Comparator.comparingInt(Candidate::getScore).reversed())
.toList();
}
public void printNames(List<Candidate> candidates) {
candidates.stream()
.map(Candidate::getName)
.forEach(System.out::println);
}
}Read the pipeline
Read a stream from top to bottom. stream starts the pipeline. filter keeps only matching items. map changes each item into another value. sorted orders the items. toList creates a new list.
The arrow in candidate -> candidate.getScore() >= 70 is a lambda. It means: for each candidate, return true if their score is at least 70.
Use streams safely
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done
Do not over-chain
A long stream can become harder to read than a loop. If you need many conditions, move them into a method with a clear name.
This is better for reviews. Another builder should understand your repo without asking you on WhatsApp.
private boolean isStrongJavaCandidate(Candidate candidate) {
return candidate.getSkills().contains("Java")
&& candidate.getScore() >= 70
&& (candidate.getCity().equalsIgnoreCase("Bengaluru")
|| candidate.isRemoteReady());
}
public List<Candidate> shortlist(List<Candidate> candidates) {
return candidates.stream()
.filter(this::isStrongJavaCandidate)
.sorted(Comparator.comparingInt(Candidate::getScore).reversed())
.toList();
}Use AI carefully
You can ask an AI tool to rewrite a loop as a stream. Then check three things yourself: it keeps the same result, it handles empty lists, and it stays readable.
Do not accept code that uses unknown libraries or changes your class names. Your final repo should build cleanly on another laptop.
Prompt:
Rewrite this Java for loop using streams. Keep the same class names and only use the Java standard library. Explain any behavior change.Do this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done