Java code examples
7 short, tested snippets. Pick one to see the code with notes, or search Zest for something specific, such as “java read a file”.
- Read a fileimport java.nio.file.*;
- Stream: filter and mapList<String> names = users.stream()
- Recordpublic record Point(int x, int y) {
- Loop over a HashMapMap<String, Integer> m = new HashMap<>();
- try-with-resourcestry (var reader = Files.newBufferedReader(Path.of("data.txt"))) {
- HTTP GET requestvar client = HttpClient.newHttpClient();
- Hello worldpublic class Main {