-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatastructures.java
More file actions
136 lines (116 loc) · 4.12 KB
/
Datastructures.java
File metadata and controls
136 lines (116 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.javadatastructures;
import java.util.*;
public class Datastructures {
public static void main(String[] args) {
// // arrays
// String [] colors = new String[5];
// colors[0] = " hai";
// System.out.println(Arrays.toString(colors));
// System.out.println(colors); // address
//
// String [] hai = {"hall", " bye"};
// System.out.println(Arrays.toString(hai));
// System.out.println(colors.length);
// // Arrays.stream(colors).forEach(System.out::print);
//
// int[][] array2d;
// // int[][] array2d = new int[2][2];
// array2d = new int[][]{
// new int[]{1,3},
// new int[]{3,5}
// };
//
// System.out.println(Arrays.deepToString(array2d));
//
// // list
// List al = new ArrayList();
// al.add("blue");
// al.add(2);
// al.add("hai");
//
// System.out.println(al);
// al.remove(2);
// System.out.println(al);
// System.out.println(al.get(0));
/// Stack
// Stack<Integer> s = new Stack<>();
// s.push(3);
// System.out.println(s.peek());
// s.push(4);
// System.out.println(s.peek());
// System.out.println(s.size());
// s.add(3);
// System.out.println(s.peek());
// Queue
// Queue<Persons> q = new LinkedList<>();
// q.add(new Persons(3, "guru"));
// q.add(new Persons(4,"mani"));
// System.out.println(q.peek());
// System.out.println(q.poll()); // removes
// System.out.println(q.peek());
// LinkedList ll = new LinkedList<>();
// ll.add(3);
// ll.add("55j");
// System.out.println(ll);
// // using iterator
// ListIterator llitr = ll.listIterator();
// while (llitr.hasNext()){
// System.out.println(llitr.next());
// }
// System.out.println("dffgfg");
// while (llitr.hasPrevious())
// System.out.println(llitr.previous());
// no duplicates in set
/// treeset prevents order
// hashset -hashmap no order use iterator
// Set<String> s = new HashSet<>();
// s.add("ha");
// s.add("dsdfd33");
// s.add("dd");
// s.add("22");
// s.forEach(System.out::println);
// /// if u use classes override equal and hashcode and toString(not neccesary) methods
// s.remove("dd");
// System.out.println("new");
// s.forEach(System.out::println);
// map -> hashtable,hashmap, sortedmap
// key value pair
// hashtable nulls not allowed stycronized
// hashmap nulls are allowed not syncronized
// hashmap -> linkedHashMap
// hashmap doubly likedlist implemantation so slow
// sortedmap -> navigableMap -> treeMap
// TreeMap sorted nulls not allowed
// map cant contain duplicates
// Map<Integer,String> student = new HashMap<>();
// student.put(1,"hai");
// student.put(2,"Alex");
// student.put(3,"ROse");
// System.out.println(student);
// // student.forEach(System.out::println); -- error
// System.out.println(student.size());
// System.out.println(student.get(2));
// System.out.println(student.keySet());
// System.out.println(student.entrySet());
// student.entrySet().forEach(System.out::println);
//
// System.out.println("woow new looping in map");
//
// student.entrySet().forEach(x -> System.out.println(x.getKey()+ " "+x.getValue()));
//
// System.out.println("another looping");
// student.values().forEach(System.out::println);
//
// System.out.println("another again");
//
//
// /// removing
// student.remove(2);
// System.out.println(student.get(2)); // returns null
// System.out.println(student);
// student.replace(1,"hkk");
// System.out.println(student);
// hash
}
static record Persons(int age, String name){};
}