Skip to content

Commit a2ca407

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 62d9256 + acf4622 commit a2ca407

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1491
-125
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ For the quick start, you can follow the steps below:
5555
1. Star <a href="https://github.com/utkarsh1504/DSA-Java" title="this">this</a> repository.
5656
2. Fork <a href="https://github.com/utkarsh1504/DSA-Java" title="this">this</a> repository.
5757
3. Clone the **forked** repository.
58+
4. Set <a href="https://github.com/utkarsh1504/DSA-Java" title="this">this</a> repository as upstream repository.
5859

5960
```yml
6061
git clone https://github.com/<your-github-username>/DSA-Java
6162
```
63+
Set upstream command
64+
```yml
65+
git remote add upstream https://github.com/Utkarsh1504/DSA-Java.git
66+
```
6267

6368
3. Navigate to the project directory.
6469

@@ -84,8 +89,8 @@ Run the following command to install the required dependencies.
8489

8590
6. Stage your changes and commit
8691

87-
```css
88-
git add -a
92+
```yml
93+
git add .
8994

9095
git commit -m "<your_commit_message>"
9196
```

lessons/arraylist.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,183 @@ order: "4B"
55
section: "Arrays"
66
description: "learn arrays"
77
---
8+
9+
The ArrayList class is in implementation of the list interface that allow us to create resizable array. In simple term we can say that ArrayList in java is dynamic array for storing the elements. It is just like the vector in c++.
10+
11+
12+
## Creating An ArrayList
13+
14+
```java
15+
ArrayList<type>arraylist = new ArrayList<> ;
16+
//here type define any type of ArrayList.
17+
Example:
18+
ArrayList<Integer> arrlist = new ArrayList<Integer>(n);
19+
20+
```
21+
22+
## Code Snippet to demonstrate the working of ArrayList in Java
23+
```java
24+
import java.io.*;
25+
import java.util.*;
26+
27+
class ArrayListExample {
28+
public static void main(String[] args)
29+
{
30+
//create array
31+
ArrayList<Integer> arr = new ArrayList<Integer>(n);
32+
33+
arr.add(1);
34+
arr.add(2);
35+
arr.add(3);
36+
arr.add(4);
37+
System.out.println("List: " + arr );
38+
}
39+
}
40+
41+
```
42+
43+
## Output
44+
```java
45+
List : [1, 2, 3, 4]
46+
```
47+
48+
## Methods OF ArrayList :
49+
Some Commonly used Methods
50+
51+
Method | Detail
52+
------------- | -------------
53+
size() | give the size of the ArrayList
54+
sort() | to sort the elements in the list
55+
isEmpty() | Checks if the arraylist is empty.
56+
indexOf() | to find index of any element.
57+
58+
59+
60+
## Basic Operation in Java ArrayList :
61+
The ArrayList class have some methods to perform different operations on arraylists. Let's see some of most used methods.
62+
63+
- Add elements
64+
- Access elements
65+
- Change elements
66+
- Remove elements
67+
68+
### Add Elements:
69+
- add() : This is the method to insert any elements at the end of the list.
70+
```java
71+
import java.util.ArrayList;
72+
73+
class Main {
74+
public static void main(String[] args){
75+
76+
ArrayList<String> playerName = new ArrayList<>();
77+
78+
// add() method
79+
playerName.add("Virat");
80+
playerName.add("Dhoni");
81+
playerName.add("Sachin");
82+
//print
83+
System.out.println("ArrayList: " + playerName);
84+
}
85+
}
86+
```
87+
### Output:
88+
89+
```
90+
ArrayList : [Virat,Dhoni,Sachin]
91+
```
92+
93+
- get() : This method is used to acess the elements from the list.
94+
95+
```java
96+
import java.util.ArrayList;
97+
98+
class Main {
99+
public static void main(String[] args){
100+
101+
ArrayList<String> playerName = new ArrayList<>();
102+
103+
104+
playerName.add("Virat");
105+
playerName.add("Dhoni");
106+
playerName.add("Sachin");
107+
System.out.println("ArrayList: " + playerName);
108+
109+
// get() method
110+
String name1 = playerName.get(1);
111+
System.out.println(name1);
112+
}
113+
}
114+
115+
```
116+
### Output:
117+
```
118+
ArrayList : [Virat,Dhoni,Sachin];
119+
Dhoni
120+
```
121+
- set(): This method is used to set any elements at any position.
122+
123+
```java
124+
import java.util.ArrayList;
125+
126+
class Main {
127+
public static void main(String[] args) {
128+
ArrayList<String> playerName = new ArrayList<>();
129+
130+
// add() method without the index parameter
131+
playerName.add("Virat");
132+
playerName.add("Dhoni");
133+
playerName.add("Sachin");
134+
System.out.println("ArrayList: " + playerName);
135+
136+
137+
// change the element of the array list
138+
playerName.set(2, "Rohit");
139+
System.out.println("New ArrayList: " + playerName);
140+
}
141+
}
142+
```
143+
### Output:
144+
```
145+
ArrayList : [Virat,Dhoni,Sachin]
146+
New ArrayList : [Virat,Dhoni,Rohit]
147+
148+
```
149+
- remove() : To remove the elements from the list
150+
151+
```java
152+
import java.util.ArrayList;
153+
154+
class Main {
155+
public static void main(String[] args) {
156+
ArrayList<String> playerName = new ArrayList<>();
157+
158+
159+
// add() method without the index parameter
160+
playerName.add("Virat");
161+
playerName.add("Dhoni");
162+
playerName.add("Sachin");
163+
System.out.println("ArrayList: " + playerName);
164+
165+
// remove element
166+
String name1 = playerName.remove(2);
167+
//print list after removal
168+
System.out.println("New ArrayList: " + playerName);
169+
//removed elements
170+
System.out.println("Removed: " + name1);
171+
}
172+
}
173+
```
174+
### Output:
175+
```
176+
ArrayList : [Virat,Dhoni,Sachin]
177+
New ArrayList : [Virat,Dhoni]
178+
Removed: Sachin
179+
```
180+
## Some remembering points about ArrayList
181+
182+
- It comes under java.util package.
183+
- This class maintains insertion order.
184+
- It allows random access.
185+
- ArrayList is not Synchronized
186+
- To convert ArrayList into an array we use toArray() method.
187+
- To converst array into an arraylist we use asList() method.

lessons/assignment.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
---
22
path: "/assignment"
33
title: "Assignments"
4-
order: "22A"
4+
order: "24A"
55
section: "Assignments & Practise Question"
66
description: "practise some standard question"
77
icon: "question"
88
---
9+
10+
This section will consist some leetcode questions and some practise questions.
11+
All the solutions will be in [LeetCode](https://github.com/utkarsh1504/leetcode-solutions) repository.
12+
13+
## Leetcode Question
14+
15+
The following is a list of leetcode questions.
16+
17+
### Arrays -
18+
19+
- [1. Two Sum](https://leetcode.com/problems/two-sum/)

lessons/backtrack-maze.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
path: "/backtrack-maze"
3+
title: "Maze Problems"
4+
order: "9E"
5+
section: "BackTracking In Java"
6+
description: "learn about backtracking algorithms"
7+
---

lessons/backtrack-nknight.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
path: "/backtrack-nknight"
3+
title: "N Knights"
4+
order: "9D"
5+
section: "BackTracking In Java"
6+
description: "learn about backtracking algorithms"
7+
---

lessons/backtrack-sudoku.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
path: "/backtrack-sudoku"
3+
title: "Sudoku Solver"
4+
order: "9B"
5+
section: "BackTracking In Java"
6+
description: "learn about backtracking algorithms"
7+
---

lessons/backtracking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
path: "/backtracking"
3-
title: "Intro"
4-
order: "11A"
3+
title: "Introduction to Backtracking"
4+
order: "9A"
55
section: "BackTracking In Java"
66
description: "learn about backtracking algorithms"
77
icon: "sitemap"

lessons/bitwise-operator.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
path: "/bitwise-operator"
3+
title: "Complete Bitwise Operators"
4+
order: "10B"
5+
section: "Maths for DSA"
6+
description: "learn maths required in DSA"
7+
---

lessons/bmmv-algorithm.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
path: "/bmmv-algorithm"
3+
title: "Boyer-Moore Majority Voting Algorithm"
4+
order: "4D"
5+
section: "Arrays"
6+
description: "arrays"
7+
icon: "map"
8+
---

lessons/bracktrack-nqueen.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
path: "/backtrack-nqueen"
3+
title: "N Queens"
4+
order: "9C"
5+
section: "BackTracking In Java"
6+
description: "learn about backtracking algorithms"
7+
---

0 commit comments

Comments
 (0)