SlideShare a Scribd company logo
1 of 11
Download to read offline
12 3 4 5
6
java.1ang.ArrayIndexOutotBoundsException: Index 6 out of bounds for length 5
Give correct index
BUILD SUCCESSFUL (total time: 7 seconds)
.va FlbonacciRecursion.javaX MergeSortWithOutExtraSpace.java X
Bstjava Xy Treejava x
ExceptionHandling java XSumOffwoNumbers.java XArayinde
History P
pusiec eLass APPEYindexxceptIon (
Source
I
public static void main (String tl args)
Scanner sc=new Scanner (System. in) ;
int size=sc.nextInt ()
int arr []=new int [size]
10
for (int i=0;i<size;i++)
Ll
arr[i]=sc.nextInt()
tryl
int index=sc
.nextInt () ;
system. out.println (arr (index] ) ;
18
19
catch (ArrayIndexoutofBoundsException e)
20
System.out.println (e) ;
System. 0ut.println ("Give correct index")
21
22
23
I
o
java. lang.Arit.hmeticException: by zero
Give correct divisor
BUILD SUCCESSFUL (total time: 4 seconds)
va
FlbonacciRecursion.java X
MergeSortWithOutExtraSpace.java X
Bstjava X
Treejava ExceptionHarndling.java XSumOfToNumbersjava
Source History e
package sumoftwonumbers;
import java.util.*
public class
Sumo fTwoNumber
public static void main (String [] args) t
Scanner sc=new Scanner (system. in);
int x=sc.nextInt ()://getting and input
int y=sc.nextInt ()i//getting an input
try{//try block
int div=x/y;
System. Out.printin ("Division of two numbers is: "+div) :
catch(ArithmeticException e){//ctach bloack
System. Out .println (e)
system. out .println ("Give correct divisor") ;
erence between Lis, set and Map in
Java
Listinterface in_Java is a sub-interface of
the Java collections interface. It contains
the index-based methods to insert, update,
delete, and search the elements. It can
have duplicate elements also. We can also
store the null elements in the list. List
preserves the insertion order, it allows
positional access and insertion of
elements. It found in the java.util package.
Let's consider an example for a better
understanding where you will see how
you can add elements by using a list
interface in java.
The Set follows the unordered way and it
found in java.util package and extends the
collection interface in java. Duplicate item
will be ignored in Set and it will not print
in the final output. Let's consider an
example for a better understanding where
you will see how you can add elements by
using a set interface in java. Let's have a
look.
The Java Map interface, java.util.Map
represents a mapping between a key and a
value. More specifically, a Java Map can
store pairs of keys and values. Each key is
linked to a specific value. Once stored in a
Map, you can later look up the value using
just the key. Let's consider an example for
better understanding where you will see
how you can add elements by using the
Map interface in java. Let's have a look.
jst set
N does not The map do
face allows
allow duplicate allow du
duplicate elements. elements
elements
do
Set
list
maintain
not
The map als
any
not
The
maintains maintai
insertion
insertion order. insertion orde
order.
The map all
We can add any But in set single null
number of null almost only one most and
values. null value. number of
values.
List
Set
implementation Map impleme
implementation
are
classes
List,
HashSet,
classes classes are Ha
are
Array HashTable, T
ConcurrentHa
LinkedHasnandLinkedHa
LinkedList.
and TreeSet.
Run
Output
1 // Online Java Compiler
java cp tmp/jLlghgvP08 Helloworld
30
2 / Use this editor to write, compile and run your Java code online
3 import java.util.*;
4 class HelloWorld {
public statiC void main(String[] args) {
Scanner sc new Scanner(System.in)
List<Integer list new ArrayList<>):
list.add(10):
list.add(20)
list.add(30);
System.out.print(list.get(2)); //get value of list at index 2
8
9
10
11
12
13
Tun
Printing before adding (10, 12, 301
printing after adding duplicate (10, 12, 301
BUILD SUcCESSEUT (total time: 0
seconds)
MergeSortWithOutExtraSpace.java Bstjava X
Tree.java ExceptionHandling.java X
SumOffwoNurnbersjava ArrayindeExcoption.jnva
History
arce
package exampleset:
import java.util.*
public class Exampleset {
public static void main(String[] args)
Scanner sC=new Scanner (system.in) ;
Set<Integer> set=new HashSet<>()
set.add (10) ;
set.add(12)
set.add(30)
System. out -println ("Printing before adding "+set);
set.add(10) 1//adding duplica te
System,out.println("printing after adding duplicate "+set)
run:
1 2 3 45
Elements in the map-> (1-0, 2-1, 3-2, 43, 5-4)
BUILD SUcCESSPUL (total t ime: 3
second)
.va BstjavaX Treejava Exception Handlingjava X
SumOflwoNumbersjava ArraylndexException.java Erampleset.java ExampleHashMapjava
Source History P 2
package examplehashmap
import
java.util.*
public class ExampleHashMap
public static void
main(Stringt] args)
Scanner sc=new
scanner(system.in)
Map Integer,Integer> map-new HashMap<> () 1//creatig an hashMap
int n-sc.nextInt ()
for (int i-01i<nii++)
int numsc.nextInt ()
map.put (num, i)1//putting intp mapP
System. out .println ("Elements in the map-> "+map)
system. out.printin(map.get(2))#//get ting an index
18
19
20
Eun
[Red, Green, Orange, White, Black]
BUILD SUCCESSFUL (total time:0 seconds)
va Tree.java X ExceptionHandling java SumOfTwoNumbers.java ArraylndexException.java ExampleSet.java X ExarmplettashMap jnva ExampleArray
Source History P 9
package examplearraylist;
import java. util. *
public class ExampleArrayList (
public static void
main (String[] args)
Scanner sc=new Scanner (System. in)
List<string> 1ist-new ArrayList<>()
list.add ("Red"):
list. add ("Green");
list.add ("Orange") ;
1ist.add ("White")1
list.add ("Black")
system.out-printin (list);
17
18
19
20
run:
Beforeremoving the third element in the 1ist [Red, Green, Orange, White, Black]
After removing the third element in the list [Red, Green, orange, Black]
BUILD SUCCESSFUL (total time: 0 seconds)
I
.va SumOffwoNumbers.java X
ArraylndexException.java ExampleSet.java X
ExampleHashMapjava ExampleArraylistjava X ExampleArraylist2.java
Source History
public static void main (Stringl] args) (
Scanner sc=new Scanner(system.in)
List<string> list=new ArrayList<> () ://creating an 1ist
10
11 list.add ("Red") ;
list.add ("Green") ;//adding
list.add ("Orange") ;
12
13
list.add("White") ;
list.add("Black")
System. Out.println ("Be fore removing the third element in the 1ist "+list) ;
list.remove(3) ;//removing|
system. out .println ("After removing the third element in the list "+list) ;
14
16
19
20

More Related Content

Similar to java set1 program.pdf

Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Most Important C language program
Most Important C language programMost Important C language program
Most Important C language program
TEJVEER SINGH
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
MaruMengesha
 

Similar to java set1 program.pdf (20)

C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Collection v3
Collection v3Collection v3
Collection v3
 
Lec2
Lec2Lec2
Lec2
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
Java Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfJava Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdf
 
Most Important C language program
Most Important C language programMost Important C language program
Most Important C language program
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015
 
Oop lecture7
Oop lecture7Oop lecture7
Oop lecture7
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Array in Java
Array in JavaArray in Java
Array in Java
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iii
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 

Recently uploaded

Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Recently uploaded (20)

Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 

java set1 program.pdf

  • 1. 12 3 4 5 6 java.1ang.ArrayIndexOutotBoundsException: Index 6 out of bounds for length 5 Give correct index BUILD SUCCESSFUL (total time: 7 seconds) .va FlbonacciRecursion.javaX MergeSortWithOutExtraSpace.java X Bstjava Xy Treejava x ExceptionHandling java XSumOffwoNumbers.java XArayinde History P pusiec eLass APPEYindexxceptIon ( Source I public static void main (String tl args) Scanner sc=new Scanner (System. in) ; int size=sc.nextInt () int arr []=new int [size] 10 for (int i=0;i<size;i++) Ll arr[i]=sc.nextInt() tryl int index=sc .nextInt () ; system. out.println (arr (index] ) ; 18 19 catch (ArrayIndexoutofBoundsException e) 20 System.out.println (e) ; System. 0ut.println ("Give correct index") 21 22 23
  • 2. I o java. lang.Arit.hmeticException: by zero Give correct divisor BUILD SUCCESSFUL (total time: 4 seconds) va FlbonacciRecursion.java X MergeSortWithOutExtraSpace.java X Bstjava X Treejava ExceptionHarndling.java XSumOfToNumbersjava Source History e package sumoftwonumbers; import java.util.* public class Sumo fTwoNumber public static void main (String [] args) t Scanner sc=new Scanner (system. in); int x=sc.nextInt ()://getting and input int y=sc.nextInt ()i//getting an input try{//try block int div=x/y; System. Out.printin ("Division of two numbers is: "+div) : catch(ArithmeticException e){//ctach bloack System. Out .println (e) system. out .println ("Give correct divisor") ;
  • 3. erence between Lis, set and Map in Java Listinterface in_Java is a sub-interface of the Java collections interface. It contains the index-based methods to insert, update, delete, and search the elements. It can have duplicate elements also. We can also store the null elements in the list. List preserves the insertion order, it allows positional access and insertion of elements. It found in the java.util package. Let's consider an example for a better understanding where you will see how you can add elements by using a list interface in java.
  • 4. The Set follows the unordered way and it found in java.util package and extends the collection interface in java. Duplicate item will be ignored in Set and it will not print in the final output. Let's consider an example for a better understanding where you will see how you can add elements by using a set interface in java. Let's have a look.
  • 5. The Java Map interface, java.util.Map represents a mapping between a key and a value. More specifically, a Java Map can store pairs of keys and values. Each key is linked to a specific value. Once stored in a Map, you can later look up the value using just the key. Let's consider an example for better understanding where you will see how you can add elements by using the Map interface in java. Let's have a look.
  • 6. jst set N does not The map do face allows allow duplicate allow du duplicate elements. elements elements do Set list maintain not The map als any not The maintains maintai insertion insertion order. insertion orde order. The map all We can add any But in set single null number of null almost only one most and values. null value. number of values. List Set implementation Map impleme implementation are classes List, HashSet, classes classes are Ha are Array HashTable, T ConcurrentHa LinkedHasnandLinkedHa LinkedList. and TreeSet.
  • 7. Run Output 1 // Online Java Compiler java cp tmp/jLlghgvP08 Helloworld 30 2 / Use this editor to write, compile and run your Java code online 3 import java.util.*; 4 class HelloWorld { public statiC void main(String[] args) { Scanner sc new Scanner(System.in) List<Integer list new ArrayList<>): list.add(10): list.add(20) list.add(30); System.out.print(list.get(2)); //get value of list at index 2 8 9 10 11 12 13
  • 8. Tun Printing before adding (10, 12, 301 printing after adding duplicate (10, 12, 301 BUILD SUcCESSEUT (total time: 0 seconds) MergeSortWithOutExtraSpace.java Bstjava X Tree.java ExceptionHandling.java X SumOffwoNurnbersjava ArrayindeExcoption.jnva History arce package exampleset: import java.util.* public class Exampleset { public static void main(String[] args) Scanner sC=new Scanner (system.in) ; Set<Integer> set=new HashSet<>() set.add (10) ; set.add(12) set.add(30) System. out -println ("Printing before adding "+set); set.add(10) 1//adding duplica te System,out.println("printing after adding duplicate "+set)
  • 9. run: 1 2 3 45 Elements in the map-> (1-0, 2-1, 3-2, 43, 5-4) BUILD SUcCESSPUL (total t ime: 3 second) .va BstjavaX Treejava Exception Handlingjava X SumOflwoNumbersjava ArraylndexException.java Erampleset.java ExampleHashMapjava Source History P 2 package examplehashmap import java.util.* public class ExampleHashMap public static void main(Stringt] args) Scanner sc=new scanner(system.in) Map Integer,Integer> map-new HashMap<> () 1//creatig an hashMap int n-sc.nextInt () for (int i-01i<nii++) int numsc.nextInt () map.put (num, i)1//putting intp mapP System. out .println ("Elements in the map-> "+map) system. out.printin(map.get(2))#//get ting an index 18 19 20
  • 10. Eun [Red, Green, Orange, White, Black] BUILD SUCCESSFUL (total time:0 seconds) va Tree.java X ExceptionHandling java SumOfTwoNumbers.java ArraylndexException.java ExampleSet.java X ExarmplettashMap jnva ExampleArray Source History P 9 package examplearraylist; import java. util. * public class ExampleArrayList ( public static void main (String[] args) Scanner sc=new Scanner (System. in) List<string> 1ist-new ArrayList<>() list.add ("Red"): list. add ("Green"); list.add ("Orange") ; 1ist.add ("White")1 list.add ("Black") system.out-printin (list); 17 18 19 20
  • 11. run: Beforeremoving the third element in the 1ist [Red, Green, Orange, White, Black] After removing the third element in the list [Red, Green, orange, Black] BUILD SUCCESSFUL (total time: 0 seconds) I .va SumOffwoNumbers.java X ArraylndexException.java ExampleSet.java X ExampleHashMapjava ExampleArraylistjava X ExampleArraylist2.java Source History public static void main (Stringl] args) ( Scanner sc=new Scanner(system.in) List<string> list=new ArrayList<> () ://creating an 1ist 10 11 list.add ("Red") ; list.add ("Green") ;//adding list.add ("Orange") ; 12 13 list.add("White") ; list.add("Black") System. Out.println ("Be fore removing the third element in the 1ist "+list) ; list.remove(3) ;//removing| system. out .println ("After removing the third element in the list "+list) ; 14 16 19 20