SlideShare a Scribd company logo
import java.util.ArrayList;
import java.util.List;
public class SearchList {
/**
* param args
*/
public static void main(String[] args) {
List list = new ArrayList();
list.add(3);
list.add(3);
list.add(1);
System.out.println("Search element 3 in list [3,3,1] :"
+ search(list, 3));
System.out.println("Search element 5 in list [3,3,1] :"
+ search(list, 5));
}
/**
* method to find the index of element in the list
* param list
* param element
* return
*/
public static int search(List list, Object element) {
int index = -1;
if (list == null || element == null)
throw new NullPointerException();
else {
int searchElement = (int) element;
for (int i = 0; i < list.size(); i++) {
int number = (int) list.get(i);
if (number == searchElement) {
index = i;
}
}
}
return index;
}
}
OUTPUT:
Search element 3 in list [3,3,1] :1
Search element 5 in list [3,3,1] :-1
Solution
import java.util.ArrayList;
import java.util.List;
public class SearchList {
/**
* param args
*/
public static void main(String[] args) {
List list = new ArrayList();
list.add(3);
list.add(3);
list.add(1);
System.out.println("Search element 3 in list [3,3,1] :"
+ search(list, 3));
System.out.println("Search element 5 in list [3,3,1] :"
+ search(list, 5));
}
/**
* method to find the index of element in the list
* param list
* param element
* return
*/
public static int search(List list, Object element) {
int index = -1;
if (list == null || element == null)
throw new NullPointerException();
else {
int searchElement = (int) element;
for (int i = 0; i < list.size(); i++) {
int number = (int) list.get(i);
if (number == searchElement) {
index = i;
}
}
}
return index;
}
}
OUTPUT:
Search element 3 in list [3,3,1] :1
Search element 5 in list [3,3,1] :-1

More Related Content

PDF
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
PDF
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
PPTX
ArrayList class and useful methods.pptx
DOCX
This class maintains a list of 4 integers. This list .docx
PDF
please read below it will tell you what we are using L.pdf
PDF
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
DOCX
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
PDF
Complete skeletonimport java.util.ArrayList; public class My.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
ArrayList class and useful methods.pptx
This class maintains a list of 4 integers. This list .docx
please read below it will tell you what we are using L.pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Complete skeletonimport java.util.ArrayList; public class My.pdf

Similar to import java.util.ArrayList; import java.util.List;public class S.pdf (20)

PDF
For this lab you will complete the class MyArrayList by implementing.pdf
PPT
A2003822018_21789_17_2018_09. ArrayList.ppt
PDF
please read the steps below and it will tell you what we usi.pdf
PDF
I need help with this code working Create another project and add yo.pdf
PPT
lec6.ppt
PPT
Engineering lecture ppt by venay magen
PDF
Please do parts labeled TODO LinkedList.java Replace.pdf
DOCX
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
PDF
import java-util-ArrayList- import java-util-Collections- import java-.pdf
PDF
we using java code DynamicArrayjava Replace all .pdf
PDF
output and explain There is Mylist There is MyArrayList pa.pdf
PPT
L11 array list
PDF
In C++Add the function min as an abstract function to the classar.pdf
PDF
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
PDF
Java ArrayList Tutorial | Edureka
PPTX
Java collections
PDF
we using java dynamicArray package modellinearpub imp.pdf
PDF
Hi,I have added the methods and main class as per your requirement.pdf
PDF
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
PDF
Preparation Data Structures 04 array linear_list
For this lab you will complete the class MyArrayList by implementing.pdf
A2003822018_21789_17_2018_09. ArrayList.ppt
please read the steps below and it will tell you what we usi.pdf
I need help with this code working Create another project and add yo.pdf
lec6.ppt
Engineering lecture ppt by venay magen
Please do parts labeled TODO LinkedList.java Replace.pdf
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
import java-util-ArrayList- import java-util-Collections- import java-.pdf
we using java code DynamicArrayjava Replace all .pdf
output and explain There is Mylist There is MyArrayList pa.pdf
L11 array list
In C++Add the function min as an abstract function to the classar.pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
Java ArrayList Tutorial | Edureka
Java collections
we using java dynamicArray package modellinearpub imp.pdf
Hi,I have added the methods and main class as per your requirement.pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Preparation Data Structures 04 array linear_list
Ad

More from anupamele (20)

PDF
Alternative 1 Continuing present jobPV = Pmt x (1 + i) x (1 - (1 .pdf
PDF
#include iostream #include fstreamusing namespace std;void.pdf
PDF
Wilhelm Johannsen first proposed the distinction between genotype a.pdf
PDF
True, they are identical Thats just the bottom vi.pdf
PDF
The NH2OH is in acidic solution as a reactant and.pdf
PDF
The atom is a basic unit of matter consisting of .pdf
PDF
see the inner one is union of events from 1-inf. .pdf
PDF
No you wouldnt include the intermediates in the.pdf
PDF
mole of NaOH= 1240 =0.3 so molarity = 0.31.8 = .pdf
PDF
millimoles of HBr=500.04=2 millimoles of KOH=25.pdf
PDF
initially 2 moles of HCl per L of water suppose x.pdf
PDF
i cant see the question.. please post the complet.pdf
PDF
hey pls give the reactions.... .pdf
PDF
FT-Raman spectra of some calcium phosphates, calc.pdf
PDF
H is oxidised here no O2 is not oxidised as it g.pdf
PDF
Current Stock price = Expected dividend (Required rate of return -.pdf
PDF
YES the news stories in the Illustrated American sympathetic or non-.pdf
PDF
Well its quite an easy one. The given curve is a cardioid. The limit.pdf
PDF
Total ionic Equation is 2Cu2+ +4 Cl - + 4H+ +SO42- --- Cu2SiO4+ 4.pdf
PDF
AnswerSOCS are the supressor of cytokine signaling proteins and a.pdf
Alternative 1 Continuing present jobPV = Pmt x (1 + i) x (1 - (1 .pdf
#include iostream #include fstreamusing namespace std;void.pdf
Wilhelm Johannsen first proposed the distinction between genotype a.pdf
True, they are identical Thats just the bottom vi.pdf
The NH2OH is in acidic solution as a reactant and.pdf
The atom is a basic unit of matter consisting of .pdf
see the inner one is union of events from 1-inf. .pdf
No you wouldnt include the intermediates in the.pdf
mole of NaOH= 1240 =0.3 so molarity = 0.31.8 = .pdf
millimoles of HBr=500.04=2 millimoles of KOH=25.pdf
initially 2 moles of HCl per L of water suppose x.pdf
i cant see the question.. please post the complet.pdf
hey pls give the reactions.... .pdf
FT-Raman spectra of some calcium phosphates, calc.pdf
H is oxidised here no O2 is not oxidised as it g.pdf
Current Stock price = Expected dividend (Required rate of return -.pdf
YES the news stories in the Illustrated American sympathetic or non-.pdf
Well its quite an easy one. The given curve is a cardioid. The limit.pdf
Total ionic Equation is 2Cu2+ +4 Cl - + 4H+ +SO42- --- Cu2SiO4+ 4.pdf
AnswerSOCS are the supressor of cytokine signaling proteins and a.pdf
Ad

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
1_English_Language_Set_2.pdf probationary
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Lesson notes of climatology university.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Empowerment Technology for Senior High School Guide
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Trump Administration's workforce development strategy
Paper A Mock Exam 9_ Attempt review.pdf.
1_English_Language_Set_2.pdf probationary
What if we spent less time fighting change, and more time building what’s rig...
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Unit 4 Skeletal System.ppt.pptxopresentatiom
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Final Presentation General Medicine 03-08-2024.pptx
Lesson notes of climatology university.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
UNIT III MENTAL HEALTH NURSING ASSESSMENT
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Chinmaya Tiranga quiz Grand Finale.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Empowerment Technology for Senior High School Guide
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين

import java.util.ArrayList; import java.util.List;public class S.pdf

  • 1. import java.util.ArrayList; import java.util.List; public class SearchList { /** * param args */ public static void main(String[] args) { List list = new ArrayList(); list.add(3); list.add(3); list.add(1); System.out.println("Search element 3 in list [3,3,1] :" + search(list, 3)); System.out.println("Search element 5 in list [3,3,1] :" + search(list, 5)); } /** * method to find the index of element in the list * param list * param element * return */ public static int search(List list, Object element) { int index = -1; if (list == null || element == null) throw new NullPointerException(); else { int searchElement = (int) element; for (int i = 0; i < list.size(); i++) { int number = (int) list.get(i); if (number == searchElement) { index = i; } } }
  • 2. return index; } } OUTPUT: Search element 3 in list [3,3,1] :1 Search element 5 in list [3,3,1] :-1 Solution import java.util.ArrayList; import java.util.List; public class SearchList { /** * param args */ public static void main(String[] args) { List list = new ArrayList(); list.add(3); list.add(3); list.add(1); System.out.println("Search element 3 in list [3,3,1] :" + search(list, 3)); System.out.println("Search element 5 in list [3,3,1] :" + search(list, 5)); } /** * method to find the index of element in the list * param list * param element * return */ public static int search(List list, Object element) { int index = -1; if (list == null || element == null) throw new NullPointerException(); else {
  • 3. int searchElement = (int) element; for (int i = 0; i < list.size(); i++) { int number = (int) list.get(i); if (number == searchElement) { index = i; } } } return index; } } OUTPUT: Search element 3 in list [3,3,1] :1 Search element 5 in list [3,3,1] :-1