This cheat sheet provides a quick reference for Java data structures and utilities, including initialization examples, common methods for strings, lists, sets, maps, stacks, and queues. It also covers tree and graph implementations, stream operations, utility functions, and time complexities for various data structures. The document serves as a concise guide for developers to efficiently utilize Java's data handling capabilities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
92 views
Java_Cheat_Sheet_Page
This cheat sheet provides a quick reference for Java data structures and utilities, including initialization examples, common methods for strings, lists, sets, maps, stacks, and queues. It also covers tree and graph implementations, stream operations, utility functions, and time complexities for various data structures. The document serves as a concise guide for developers to efficiently utilize Java's data handling capabilities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Java Data Structures & Utilities - One Page Cheat Sheet
Initialization Examples
String str = "hello"; StringBuilder sb = new StringBuilder();
List<String> list = new ArrayList<>(); Set<String> set = new HashSet<>(); Map<Integer, Integer> map = new HashMap<>(); Hashtable<Integer, String> ht = new Hashtable<>(); Queue<Integer> queue = new LinkedList<>(); Stack<Integer> stack = new Stack<>();
Map<Integer, List<Integer>> graph = new HashMap<>();
graph.computeIfAbsent(u, k -> new ArrayList<>()).add(v); Queue<Integer> q = new LinkedList<>(); Set<Integer> visited = new HashSet<>(); q.offer(start); while (!q.isEmpty()) { int node = q.poll(); for (int n : graph.getOrDefault(node, new ArrayList<>())) { if (!visited.contains(n)) { visited.add(n); q.offer(n); } } }
Streams
list.stream().filter(x -> x > 10).collect(Collectors.toList()); // > 10
String str = Integer.toString(123); int n = Integer.parseInt("123"); List<String> list = Arrays.asList("a", "b"); String joined = String.join(",", list);