SlideShare a Scribd company logo
1 of 3
Download to read offline
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

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

JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfarpaqindia
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdfarshin9
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfJAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfsuresh640714
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxVictorzH8Bondx
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfDesign your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfprajeetjain
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfarishmarketing21
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfAugstore
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfStewart29UReesa
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfrishabjain5053
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdfaryan9007
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxSHIVA101531
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
 

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

JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
강의자료9
강의자료9강의자료9
강의자료9
 
Chapter14
Chapter14Chapter14
Chapter14
 
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfJAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfDesign your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdf
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfNote- Can someone help me with the public boolean isEmpty()- public bo.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
 
Ds notes
Ds notesDs notes
Ds notes
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
Groovy
GroovyGroovy
Groovy
 

More from anupamele

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

More from anupamele (20)

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

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

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