0% found this document useful (0 votes)
6 views2 pages

Java Sheet

Uploaded by

Abhishek Nagar
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
6 views2 pages

Java Sheet

Uploaded by

Abhishek Nagar
Copyright
© © All Rights Reserved
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/ 2

Java

Complete Java Data Structures & Functions Table


Category Declaration Commonly Used Methods Traversal

Arrays.sort(arr) , Arrays.fill(arr, val) , for(int i = 0; i < arr.length; i++) {


1D Array int[] arr = new int[5]; Arrays.binarySearch(arr, key) , //Code
Arrays.toString(arr) }

for(int i = 0; i < matrix.length; i++) {


for(int j = 0; j < matrix[i].length; j++) {
Arrays.deepToString(matrix) ,
2D Array int[][] matrix = new int[3][3]; //Code
Arrays.fill(matrix[i], val)
}
}

for (int i = 0; i < list.size(); i++) {


for (int j = 0; j < list.get(i).size(); j++) {
List of Lists (2D List<List<Integer>> list = new list.add(new ArrayList<>()); , int num = list.get(i).get(j);
List) ArrayList<>(); list.get(i).add(val); , list.size() // Process num
}
}

list.add(val) , list.get(i) , list.set(i, for(int i = 0; i < list.size(); i++) {


ArrayList<Integer> list = new
ArrayList val) , list.remove(i) , //Code
ArrayList<>();
Collections.sort(list) }

for(int i = 0; i < ll.size(); i++) {


LinkedList<Integer> ll = new ll.add(val) , ll.addFirst(val) ,
LinkedList //Code
LinkedList<>(); ll.addLast(val) , ll.remove(i)
}

for(Node temp = head; temp != null;


class Node { int data; Node prev, temp = temp.next) {
Doubly LinkedList head.next , head.prev , head.data
next; } //Code
}

for(Node temp = head; temp.next !=


tail.next = head; (for circular head; temp = temp.next) {
Circular LinkedList class Node { int data; Node next; }
behavior) //Code
}

for(int i = 0; i < graph.size(); i++) {


for(int j = 0; j < graph.get(i).size(); j++)
Graph (Adjacency List<List<Integer>> graph = new {
graph.get(i).add(node) , graph.size()
List) ArrayList<>(); //Code
}
}

for(int i = 0; i < V; i++) {


for(int j = 0; j < V; j++) {
Graph (Adjacency
int[][] graph = new int[V][V]; graph[i][j] = 1; , graph[i][j] == 1 //Code
Matrix) }
}

List<Integer> list = new ArrayList<>


(set);
HashSet<Integer> set = new set.add(val) , set.remove(val) , for (int i = 0; i < list.size(); i++) {
HashSet
HashSet<>(); set.contains(val) , set.size() int num = list.get(i);
// Process num
}

List<Integer> list = new ArrayList<>


(ts);
TreeSet (Sorted TreeSet<Integer> ts = new ts.add(val) , ts.first() , ts.last() , for (int i = 0; i < list.size(); i++) {
Set) TreeSet<>(); ts.floor(val) , ts.ceiling(val) int num = list.get(i);
// Process num
}

List<Map.Entry<Integer, String>> list =


new ArrayList<>(map.entrySet());
for (int i = 0; i < list.size(); i++) {
map.put(key, val) , map.get(key) , Map.Entry<Integer, String> e =
HashMap (Key- HashMap<Integer, String> map =
map.containsKey(key) , list.get(i);
Value Pair) new HashMap<>();
map.remove(key) int key = e.getKey();
String value = e.getValue();
// Process key and value
}

TreeMap (Sorted TreeMap<Integer, String> tmap = tmap.put(key, val) , tmap.firstKey() , List<Map.Entry<Integer, String>> list =
new TreeMap<>(); new ArrayList<>(tmap.entrySet());
Key-Value) tmap.lastKey() , tmap.floorKey(key)
for (int i = 0; i < list.size(); i++) {
Map.Entry<Integer, String> e =

Java 1
list.get(i);
int key = e.getKey();
String value = e.getValue();
// Process key and value
}

PriorityQueue (Min PriorityQueue<Integer> pq = new pq.add(val) , pq.poll() , pq.peek() ,


while(!pq.isEmpty()) pq.poll();
Heap) PriorityQueue<>(); pq.isEmpty()

PriorityQueue<Integer> pq = new
PriorityQueue
PriorityQueue<> pq.add(val) , pq.poll() , pq.peek() while(!pq.isEmpty()) pq.poll();
(Max Heap) (Collections.reverseOrder());

List<Integer> list = new ArrayList<>


(dq);
for (int i = 0; i < list.size(); i++) {
Deque (Double- Deque<Integer> dq = new dq.addFirst(val) , dq.addLast(val) ,
int num = list.get(i);
Ended Queue) ArrayDeque<>(); dq.removeFirst() , dq.removeLast()
System.out.println(num); // Process
num
}

Stack<Integer> stack = new Stack<> stack.push(val) , stack.pop() ,


Stack while(!stack.isEmpty()) stack.pop();
(); stack.peek() , stack.isEmpty()

str.length() , str.charAt(i) ,
for(int i = 0; i < str.length(); i++) {
str.substring(a, b) , str.contains(str) ,
String String str = "hello"; //Code
str.toUpperCase() , str.toLowerCase() , }
str.replace(old, new) , str.trim()

for(int i = 0; i < sb.length(); i++) {


StringBuilder sb = new sb.append(val) , sb.insert(i, val) ,
StringBuilder //Code
StringBuilder("hello"); sb.delete(a, b) , sb.reverse()
}

for(int i = 0; i < sf.length(); i++) {


StringBuffer sf = new sf.append(val) , sf.insert(i, val) ,
StringBuffer //Code
StringBuffer("hello"); sf.delete(a, b) , sf.reverse()
}

Math.abs(x) , Math.sqrt(x) ,
Math.pow(a, b) , Math.max(a, b) ,
Math Functions import java.lang.Math; -
Math.min(a, b) , Math.round(x) ,
Math.floor(x) , Math.ceil(x)

Arrays.sort(arr) , Arrays.toString(arr) ,
Arrays.binarySearch(arr, key) ,
Array Functions import java.util.Arrays; -
Arrays.copyOf(arr, newSize) ,
Arrays.equals(arr1, arr2)

Collections.sort(list) ,
Collections.reverse(list) ,
Collection
import java.util.Collections; Collections.max(list) , -
Functions
Collections.min(list) ,
Collections.shuffle(list)

System.out.println(x) ,
import java.io.*; import Scanner.nextInt() ,
I/O Functions -
java.util.Scanner; Scanner.nextLine() ,
BufferedReader.readLine()

Java 2

You might also like