Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 85cb408

Browse files
Added code for Module 6
1 parent 21b2603 commit 85cb408

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

‎Module 6/ArrayListEx.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author chandrikadeb
10+
*/
11+
import java.io.*;
12+
import java.util.*;
13+
public class ArrayListEx
14+
{
15+
public static void main(String[] args) throws IOException
16+
{
17+
// size of ArrayList
18+
int n = 5,num,del;
19+
20+
//declaring ArrayList with initial size n
21+
ArrayList<Integer> arrli = new ArrayList<Integer>(n);
22+
23+
// Appending the new element at the end of the list
24+
System.out.println("Enter number of elements to add");
25+
Scanner sc=new Scanner(System.in);
26+
num=sc.nextInt();
27+
System.out.println("Enter "+num+" elements one by one:");
28+
for(int i=0;i<num;i++)
29+
{
30+
i=sc.nextInt();
31+
arrli.add(i);
32+
}
33+
// Printing elements
34+
System.out.println("After adding elements:"+arrli);
35+
36+
// Remove element at index 3
37+
System.out.println("Enter index of element to remove:");
38+
del=sc.nextInt();
39+
arrli.remove(del);
40+
41+
// Displaying ArrayList after deletion
42+
System.out.println("After deleting " +del+ "th element we get:" +arrli);
43+
44+
// Printing index
45+
System.out.println(del);
46+
}
47+
}

‎Module 6/HashMapJava.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author chandrikadeb
10+
*/
11+
import java.util.*;
12+
public class HashMapJava {
13+
public static void main(String[] args) {
14+
15+
HashMap <Integer,String> map = new HashMap<Integer,String>();
16+
Scanner in = new Scanner(System.in);
17+
System.out.println("Enter 3 key-value (integer-string) pairs one by one:");
18+
for(int i=0;i<3;i++){
19+
20+
Integer a=in.nextInt();
21+
String b=in.next();
22+
23+
map.put(a,b);
24+
}
25+
26+
// Get keys and values
27+
for (Map.Entry<Integer, String> entry : map.entrySet()) {
28+
Integer k = entry.getKey();
29+
String v = entry.getValue();
30+
System.out.println("Key: " + k + ", Value: " + v);
31+
}
32+
}
33+
}
34+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /