SlideShare a Scribd company logo
1 of 2
Download to read offline
Write a method countUnique that takes a List of integers as a parameter and returns the number
of unique integer values in the list. Use a Set as auxiliary storage to help you solve this problem.
For example, if a list contains the values [3, 7, 3, -1, 2, 3, 7, 2, 15, 15], your method should
return 5. The empty list contains 0 unique values.
Solution
package arraylistexample;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class ARRAYLISTEXAMPLE {
public static void main(String[] args) {
List list = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter some numbers..");
System.out.println("Press any non integer(Either Float or character ) for ending the input");
while (scanner.hasNextInt()) {
int i = scanner.nextInt();
list.add(i);
}
int k = alok.countUnique(list);
System.out.print(" Total number of unique elements Are : t" + k);
}
}
class alok {
public static int countUnique(List lst) {
Set set = new HashSet<>(lst);
System.out.println("Set values .....");
set.stream().forEach((temp) -> {
System.out.print(temp + "t");
});
int n = set.size();
return n;
}
}

More Related Content

Similar to Write a method countUnique that takes a List of integers as a parame.pdf

Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Java Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxJava Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxmichael1810
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfRAJATCHUGH12
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfimport java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfshettysachin2005
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
I really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdfI really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdfdbrienmhompsonkath75
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdffashioncollection2
 

Similar to Write a method countUnique that takes a List of integers as a parame.pdf (13)

Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Java Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxJava Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docx
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
 
22.ppt
22.ppt22.ppt
22.ppt
 
Lec2
Lec2Lec2
Lec2
 
Java -lec-5
Java -lec-5Java -lec-5
Java -lec-5
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Java arrays
Java   arraysJava   arrays
Java arrays
 
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfimport java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
 
Array data structure
Array data structureArray data structure
Array data structure
 
I really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdfI really need help with the code for this in Java.Set operations u.pdf
I really need help with the code for this in Java.Set operations u.pdf
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdf
 

More from MALASADHNANI

I have two statistics questions, I was wondering if you could answer.pdf
I have two statistics questions, I was wondering if you could answer.pdfI have two statistics questions, I was wondering if you could answer.pdf
I have two statistics questions, I was wondering if you could answer.pdfMALASADHNANI
 
How does increased transcription (mutation in the G1-S- checkpoint p.pdf
How does increased transcription (mutation in the G1-S- checkpoint p.pdfHow does increased transcription (mutation in the G1-S- checkpoint p.pdf
How does increased transcription (mutation in the G1-S- checkpoint p.pdfMALASADHNANI
 
How many different phases would a 4-PSK modulated signal with the fo.pdf
How many different phases would a 4-PSK modulated signal with the fo.pdfHow many different phases would a 4-PSK modulated signal with the fo.pdf
How many different phases would a 4-PSK modulated signal with the fo.pdfMALASADHNANI
 
how to get pure culture from mix culture. Microbiologyhow to.pdf
how to get pure culture from mix culture. Microbiologyhow to.pdfhow to get pure culture from mix culture. Microbiologyhow to.pdf
how to get pure culture from mix culture. Microbiologyhow to.pdfMALASADHNANI
 
from mendels time to the 1950s, what were the three model organism.pdf
from mendels time to the 1950s, what were the three model organism.pdffrom mendels time to the 1950s, what were the three model organism.pdf
from mendels time to the 1950s, what were the three model organism.pdfMALASADHNANI
 
File yuan.h#include iostream#include fstream#include .pdf
File yuan.h#include iostream#include fstream#include .pdfFile yuan.h#include iostream#include fstream#include .pdf
File yuan.h#include iostream#include fstream#include .pdfMALASADHNANI
 
diastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdf
diastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdfdiastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdf
diastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdfMALASADHNANI
 
Discuss how human activities influence some aspect of its life ando.pdf
Discuss how  human activities influence some aspect of its life ando.pdfDiscuss how  human activities influence some aspect of its life ando.pdf
Discuss how human activities influence some aspect of its life ando.pdfMALASADHNANI
 
Early in my auditing career, I always wondered how do I know when .pdf
Early in my auditing career, I always wondered how do I know when .pdfEarly in my auditing career, I always wondered how do I know when .pdf
Early in my auditing career, I always wondered how do I know when .pdfMALASADHNANI
 
Discus the development of the fraud examinerforensic accounting pro.pdf
Discus the development of the fraud examinerforensic accounting pro.pdfDiscus the development of the fraud examinerforensic accounting pro.pdf
Discus the development of the fraud examinerforensic accounting pro.pdfMALASADHNANI
 
Could a cell survive by having just peripheral proteins on it’s memb.pdf
Could a cell survive by having just peripheral proteins on it’s memb.pdfCould a cell survive by having just peripheral proteins on it’s memb.pdf
Could a cell survive by having just peripheral proteins on it’s memb.pdfMALASADHNANI
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfMALASADHNANI
 
cell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdf
cell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdfcell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdf
cell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdfMALASADHNANI
 
C++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdfC++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdfMALASADHNANI
 
Briefly discuss five criteria used to classify an organism as a multi.pdf
Briefly discuss five criteria used to classify an organism as a multi.pdfBriefly discuss five criteria used to classify an organism as a multi.pdf
Briefly discuss five criteria used to classify an organism as a multi.pdfMALASADHNANI
 
Which of the following statements about detritivores is true they a.pdf
Which of the following statements about detritivores is true  they a.pdfWhich of the following statements about detritivores is true  they a.pdf
Which of the following statements about detritivores is true they a.pdfMALASADHNANI
 
What is the role of anaerobic cellular respiration in the nitrogen c.pdf
What is the role of anaerobic cellular respiration in the nitrogen c.pdfWhat is the role of anaerobic cellular respiration in the nitrogen c.pdf
What is the role of anaerobic cellular respiration in the nitrogen c.pdfMALASADHNANI
 
What is on Important difference between genetic dissection and genomi.pdf
What is on Important difference between genetic dissection and genomi.pdfWhat is on Important difference between genetic dissection and genomi.pdf
What is on Important difference between genetic dissection and genomi.pdfMALASADHNANI
 
Ralph has seven different colors of leftover paint. Since the.pdf
Ralph has seven different colors of leftover paint. Since the.pdfRalph has seven different colors of leftover paint. Since the.pdf
Ralph has seven different colors of leftover paint. Since the.pdfMALASADHNANI
 
The following figure shows two possible groups of species on which to.pdf
The following figure shows two possible groups of species on which to.pdfThe following figure shows two possible groups of species on which to.pdf
The following figure shows two possible groups of species on which to.pdfMALASADHNANI
 

More from MALASADHNANI (20)

I have two statistics questions, I was wondering if you could answer.pdf
I have two statistics questions, I was wondering if you could answer.pdfI have two statistics questions, I was wondering if you could answer.pdf
I have two statistics questions, I was wondering if you could answer.pdf
 
How does increased transcription (mutation in the G1-S- checkpoint p.pdf
How does increased transcription (mutation in the G1-S- checkpoint p.pdfHow does increased transcription (mutation in the G1-S- checkpoint p.pdf
How does increased transcription (mutation in the G1-S- checkpoint p.pdf
 
How many different phases would a 4-PSK modulated signal with the fo.pdf
How many different phases would a 4-PSK modulated signal with the fo.pdfHow many different phases would a 4-PSK modulated signal with the fo.pdf
How many different phases would a 4-PSK modulated signal with the fo.pdf
 
how to get pure culture from mix culture. Microbiologyhow to.pdf
how to get pure culture from mix culture. Microbiologyhow to.pdfhow to get pure culture from mix culture. Microbiologyhow to.pdf
how to get pure culture from mix culture. Microbiologyhow to.pdf
 
from mendels time to the 1950s, what were the three model organism.pdf
from mendels time to the 1950s, what were the three model organism.pdffrom mendels time to the 1950s, what were the three model organism.pdf
from mendels time to the 1950s, what were the three model organism.pdf
 
File yuan.h#include iostream#include fstream#include .pdf
File yuan.h#include iostream#include fstream#include .pdfFile yuan.h#include iostream#include fstream#include .pdf
File yuan.h#include iostream#include fstream#include .pdf
 
diastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdf
diastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdfdiastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdf
diastole; systole; atriaThe cardiac cycle refers to the rhythmic rel.pdf
 
Discuss how human activities influence some aspect of its life ando.pdf
Discuss how  human activities influence some aspect of its life ando.pdfDiscuss how  human activities influence some aspect of its life ando.pdf
Discuss how human activities influence some aspect of its life ando.pdf
 
Early in my auditing career, I always wondered how do I know when .pdf
Early in my auditing career, I always wondered how do I know when .pdfEarly in my auditing career, I always wondered how do I know when .pdf
Early in my auditing career, I always wondered how do I know when .pdf
 
Discus the development of the fraud examinerforensic accounting pro.pdf
Discus the development of the fraud examinerforensic accounting pro.pdfDiscus the development of the fraud examinerforensic accounting pro.pdf
Discus the development of the fraud examinerforensic accounting pro.pdf
 
Could a cell survive by having just peripheral proteins on it’s memb.pdf
Could a cell survive by having just peripheral proteins on it’s memb.pdfCould a cell survive by having just peripheral proteins on it’s memb.pdf
Could a cell survive by having just peripheral proteins on it’s memb.pdf
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
 
cell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdf
cell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdfcell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdf
cell nuclei experiment1. What is function of SDS and O.5M NaCl in .pdf
 
C++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdfC++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdf
 
Briefly discuss five criteria used to classify an organism as a multi.pdf
Briefly discuss five criteria used to classify an organism as a multi.pdfBriefly discuss five criteria used to classify an organism as a multi.pdf
Briefly discuss five criteria used to classify an organism as a multi.pdf
 
Which of the following statements about detritivores is true they a.pdf
Which of the following statements about detritivores is true  they a.pdfWhich of the following statements about detritivores is true  they a.pdf
Which of the following statements about detritivores is true they a.pdf
 
What is the role of anaerobic cellular respiration in the nitrogen c.pdf
What is the role of anaerobic cellular respiration in the nitrogen c.pdfWhat is the role of anaerobic cellular respiration in the nitrogen c.pdf
What is the role of anaerobic cellular respiration in the nitrogen c.pdf
 
What is on Important difference between genetic dissection and genomi.pdf
What is on Important difference between genetic dissection and genomi.pdfWhat is on Important difference between genetic dissection and genomi.pdf
What is on Important difference between genetic dissection and genomi.pdf
 
Ralph has seven different colors of leftover paint. Since the.pdf
Ralph has seven different colors of leftover paint. Since the.pdfRalph has seven different colors of leftover paint. Since the.pdf
Ralph has seven different colors of leftover paint. Since the.pdf
 
The following figure shows two possible groups of species on which to.pdf
The following figure shows two possible groups of species on which to.pdfThe following figure shows two possible groups of species on which to.pdf
The following figure shows two possible groups of species on which to.pdf
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Write a method countUnique that takes a List of integers as a parame.pdf

  • 1. Write a method countUnique that takes a List of integers as a parameter and returns the number of unique integer values in the list. Use a Set as auxiliary storage to help you solve this problem. For example, if a list contains the values [3, 7, 3, -1, 2, 3, 7, 2, 15, 15], your method should return 5. The empty list contains 0 unique values. Solution package arraylistexample; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; public class ARRAYLISTEXAMPLE { public static void main(String[] args) { List list = new ArrayList<>(); Scanner scanner = new Scanner(System.in); System.out.print("Enter some numbers.."); System.out.println("Press any non integer(Either Float or character ) for ending the input"); while (scanner.hasNextInt()) { int i = scanner.nextInt(); list.add(i); } int k = alok.countUnique(list); System.out.print(" Total number of unique elements Are : t" + k); } } class alok { public static int countUnique(List lst) { Set set = new HashSet<>(lst); System.out.println("Set values ....."); set.stream().forEach((temp) -> { System.out.print(temp + "t"); }); int n = set.size();