Skip to content

Instantly share code, notes, and snippets.

@gdejohn gdejohn/Record.java Secret
Last active Apr 29, 2016

Embed
What would you like to do?
import static java.lang.Integer.parseInt;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.minBy;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Record {
int id;
String course;
int grade;
Record(String record) {
String[] values = record.split("\\|");
this.id = parseInt(values[0]);
this.course = values[1];
this.grade = parseInt(values[2]);
}
public static void main(String[] args) throws IOException {
Files.lines(Paths.get(args[0]))
.map(Record::new)
.collect(groupingBy(record -> record.course, minBy(comparing(record -> record.id))))
.forEach((course, record) -> System.out.printf("%s %d%n", course, record.get().grade));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.