0% found this document useful (0 votes)
4 views

Better_Java_Cheat_Sheet

This document is a cheat sheet for Java data structures and string operations, providing syntax and common methods for arrays, ArrayLists, LinkedLists, HashSets, TreeSets, HashMaps, TreeMaps, queues, deques, stacks, priority queues, and string manipulations. It includes examples of how to create, manipulate, and retrieve data from these structures. Additionally, it lists utility functions for sorting, searching, and comparing collections.

Uploaded by

Ola Alshatnawi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Better_Java_Cheat_Sheet

This document is a cheat sheet for Java data structures and string operations, providing syntax and common methods for arrays, ArrayLists, LinkedLists, HashSets, TreeSets, HashMaps, TreeMaps, queues, deques, stacks, priority queues, and string manipulations. It includes examples of how to create, manipulate, and retrieve data from these structures. Additionally, it lists utility functions for sorting, searching, and comparing collections.

Uploaded by

Ola Alshatnawi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Data Structures & String Cheat Sheet

Array

- int[] arr = new int[5];

- arr.length

- Arrays.sort(arr);

- Arrays.copyOf(arr, len);

ArrayList

- list.add(value);

- list.add(index, value);

- list.get(index);

- list.set(index, value);

- list.remove(index);

- list.contains(value);

- list.size();

- list.clear();

- list.indexOf(value);

- list.isEmpty();

- list.toArray();

LinkedList

- list.addFirst(value);

- list.addLast(value);

- list.removeFirst();

- list.removeLast();

- list.peekFirst();

- list.peekLast();

HashSet

- set.add(value);

- set.remove(value);

- set.contains(value);

- set.isEmpty();
- set.size();

TreeSet

- tree.add(value);

- tree.first();

- tree.last();

- tree.floor(value);

- tree.ceiling(value);

HashMap

- map.put(key, value);

- map.get(key);

- map.containsKey(key);

- map.containsValue(value);

- map.remove(key);

- map.keySet();

- map.values();

- map.entrySet();

TreeMap

- map.firstKey();

- map.lastKey();

- map.lowerKey(key);

- map.higherKey(key);

Queue (LinkedList)

- queue.add(value);

- queue.poll();

- queue.peek();

- queue.isEmpty();

Deque (ArrayDeque)

- deque.addFirst(value);

- deque.addLast(value);

- deque.removeFirst();

- deque.removeLast();
- deque.peekFirst();

- deque.peekLast();

Stack

- stack.push(value);

- stack.pop();

- stack.peek();

- stack.isEmpty();

PriorityQueue

- pq.add(value);

- pq.poll();

- pq.peek();

String

- str.length();

- str.charAt(index);

- str.substring(start, end);

- str.indexOf(sub);

- str.lastIndexOf(sub);

- str.contains(sub);

- str.equals(other);

- str.equalsIgnoreCase(other);

- str.toLowerCase();

- str.toUpperCase();

- str.trim();

- str.replace(old, new);

- str.split(delimiter);

- String.valueOf(x);

Utilities

- Arrays.sort(array);

- Arrays.binarySearch(array, value);

- Arrays.equals(arr1, arr2);

- Collections.sort(list);

- Collections.reverse(list);
- Collections.max(list);

- Collections.min(list);

- Collections.frequency(list, item);

You might also like