#409 Implementing SQL JOIN for Lists
The comments contain an SQL query. Implement an equivalent of this query in the join() method.
public class MainJava {
/*
SELECT
left.K,
left.V1,
right.V2
FROM left
JOIN right ON left.K = right.K;
*/
public <K extends Comparable<K>, V1, V2> List<Triple<K, V1, V2>> join(List<Pair<K, V1>> left, List<Pair<K, V2>> right) {
return null; // code here
}
private static class Pair<A, B> {
private A first;
private B second;
Pair(A first, B second) {
this.first = first;
this.second = second;
}
}
private static class Triple<A, B, C> {
private A first;
private B second;
private C third;
Triple(A first, B second, C third) {
this.first = first;
this.second = second;
this.third = third;
}
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor