SlideShare a Scribd company logo
output and explain
There is Mylist;
There is MyArrayList:
package com.mycompany.myarraylist;
import java.util.*;
public class MyArrayList<E> implements MyList<E> {
private class ArrayListIterator implements Iterator<E> {
private int index;
public ArrayListIterator() {
index=0;
}
public boolean hasNext() {
return index < size();
}
public E next() {
index++;
return arr[index-1];
}
public void remove() {
throw new UnsupportedOperationException();
}
}
private E[] arr;
private int logicalLength;
public MyArrayList(int initCapacity) {
arr = (E[]) new Object[initCapacity];
logicalLength = 0;
}
public MyArrayList() {
this(4);
}
public boolean add(E e) {
if(isFull())
grow();
arr[logicalLength] = e;
logicalLength++;
return true;
}
public void add(int index, E element) {
if(isOutOfBounds(index))
throw new IndexOutOfBoundsException(index + " doesn't exist");
if(isFull())
grow();
for(int i=size()-1; i>=index; i--)
arr[i+1] = arr[i];
arr[index] = element;
logicalLength++;
}
public void clear() {
logicalLength = 0;
}
public boolean contains(Object obj) {
return indexOf(obj) != -1;
}
public boolean equals(Object obj) {
if(!(obj instanceof MyArrayList))
return false;
MyArrayList<E> another = (MyArrayList<E>)obj;
if(size() != another.size())
return false;
for(int i=0; i<size(); i++)
if(! (arr[i].equals(another.arr[i])))
return false;
return true;
}
public E get(int index) {
if(isOutOfBounds(index))
throw new IndexOutOfBoundsException(index + " doesn't exist");
return arr[index];
}
public E set(int index, E element) {
if(isOutOfBounds(index))
throw new IndexOutOfBoundsException(index + " doesn't exist");
E answer = arr[index];
arr[index] = element;
return answer;
}
public int indexOf(Object obj) {
for(int i=0; i<size(); i++)
if(arr[i].equals(obj))
return i;
return -1;
}
public boolean isEmpty() {
return size()==0;
}
public int size() {
return logicalLength;
}
public Iterator<E> iterator() {
return new ArrayListIterator();
}
public int lastIndexOf(Object obj) {
for(int i=size()-1; i>=0; i--)
if(arr[i].equals(obj))
return i;
return -1;
}
public E remove(int index) {
if(isOutOfBounds(index))
throw new IndexOutOfBoundsException(index + " doesn't exist");
E data = arr[index];
for(int i=index+1; i<size(); i++)
arr[i-1] = arr[i];
logicalLength--;
return data;
}
public boolean remove(Object obj) {
int index = indexOf(obj);
if(index==-1)
return false;
remove(index);
return true;
}
public String toString() {
StringBuilder sb = new StringBuilder("[ ");
for(int i=0; i<logicalLength; i++) {
sb.append(arr[i]);
if(i < logicalLength-1)
sb.append(", ");
}
sb.append("]");
return sb.toString();
}
private void grow() {
int newCapacity = 2 * arr.length;
E[] temp = (E[]) new Object[newCapacity];
for(int i=0; i<logicalLength; i++)
temp[i] = arr[i];
arr = temp;
}
private boolean isFull() {
return logicalLength == arr.length;
}
private boolean isOutOfBounds(int index) {
return index<0 || index>=logicalLength;
}
public static void main(String[] args) {
MyArrayList<Integer> list = new MyArrayList<Integer>();
for(int i=0; i<10; i++)
list.add(i+10);
for(Iterator<Integer> it = list.iterator(); it.hasNext(); ) {
System.out.println(it.next());
}
for(int x: list)
System.out.println(x);
System.out.println(list);
list.remove((Integer)10);
System.out.println(list);
}
}

More Related Content

Similar to output and explain There is Mylist There is MyArrayList pa.pdf

6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
DEVTYPE
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magen
venaymagen19
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2Technopark
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
sales88
 
Please use Java to solve the following So.pdf
Please use Java to solve the following So.pdfPlease use Java to solve the following So.pdf
Please use Java to solve the following So.pdf
cronkwurphyb44502
 
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdfsumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
ankit482504
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
jagriti srivastava
 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
abbecindia
 
ISCP internal.pdf
ISCP internal.pdfISCP internal.pdf
ISCP internal.pdf
GANDHAMKUMAR2
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
hemanth248901
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Codemotion
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basicsopenbala
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdf
mohamednihalshahru
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
package lab7 public class SetOperations public static.pdf
package lab7     public class SetOperations  public static.pdfpackage lab7     public class SetOperations  public static.pdf
package lab7 public class SetOperations public static.pdf
syedabdul78662
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
Stewartt0kJohnstonh
 
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docxJAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
GavinUJtMathist
 

Similar to output and explain There is Mylist There is MyArrayList pa.pdf (20)

6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magen
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
 
Please use Java to solve the following So.pdf
Please use Java to solve the following So.pdfPlease use Java to solve the following So.pdf
Please use Java to solve the following So.pdf
 
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdfsumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
 
ISCP internal.pdf
ISCP internal.pdfISCP internal.pdf
ISCP internal.pdf
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basics
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
package lab7 public class SetOperations public static.pdf
package lab7     public class SetOperations  public static.pdfpackage lab7     public class SetOperations  public static.pdf
package lab7 public class SetOperations public static.pdf
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docxJAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
 

More from access2future1

The following stockholders equity accounts arranged alphabe.pdf
The following stockholders equity accounts arranged alphabe.pdfThe following stockholders equity accounts arranged alphabe.pdf
The following stockholders equity accounts arranged alphabe.pdf
access2future1
 
You are considering a stock investment in one of two firms .pdf
You are considering a stock investment in one of two firms .pdfYou are considering a stock investment in one of two firms .pdf
You are considering a stock investment in one of two firms .pdf
access2future1
 
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdfThe Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
access2future1
 
Second Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdfSecond Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdf
access2future1
 
Researchers found that a person in a particular country spen.pdf
Researchers found that a person in a particular country spen.pdfResearchers found that a person in a particular country spen.pdf
Researchers found that a person in a particular country spen.pdf
access2future1
 
QUESTION 2 internal rate of return method 14 RETURN USE N.pdf
QUESTION 2 internal rate of return method 14 RETURN  USE N.pdfQUESTION 2 internal rate of return method 14 RETURN  USE N.pdf
QUESTION 2 internal rate of return method 14 RETURN USE N.pdf
access2future1
 
Question 17 Which of the following contributes directly to t.pdf
Question 17 Which of the following contributes directly to t.pdfQuestion 17 Which of the following contributes directly to t.pdf
Question 17 Which of the following contributes directly to t.pdf
access2future1
 
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdfProporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
access2future1
 
Please Use SWISH and write the code answer each part carefu.pdf
Please Use SWISH and write the code answer each part carefu.pdfPlease Use SWISH and write the code answer each part carefu.pdf
Please Use SWISH and write the code answer each part carefu.pdf
access2future1
 
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdfPLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
access2future1
 
please help with the fill in the blanks Fill in the followin.pdf
please help with the fill in the blanks Fill in the followin.pdfplease help with the fill in the blanks Fill in the followin.pdf
please help with the fill in the blanks Fill in the followin.pdf
access2future1
 
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdfPatient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
access2future1
 
Please fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdfPlease fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdf
access2future1
 
Name the hormones that influence the menstrual cycle Ident.pdf
Name the hormones that influence the menstrual cycle  Ident.pdfName the hormones that influence the menstrual cycle  Ident.pdf
Name the hormones that influence the menstrual cycle Ident.pdf
access2future1
 
Mike and Carol Brady realized that their house was not big e.pdf
Mike and Carol Brady realized that their house was not big e.pdfMike and Carol Brady realized that their house was not big e.pdf
Mike and Carol Brady realized that their house was not big e.pdf
access2future1
 
Debugging C Console Program Debug the program to identify .pdf
Debugging C Console Program Debug the program to identify .pdfDebugging C Console Program Debug the program to identify .pdf
Debugging C Console Program Debug the program to identify .pdf
access2future1
 
742 Example 743 Continued Suppose that we have iid Ber.pdf
742 Example 743 Continued Suppose that we have iid Ber.pdf742 Example 743 Continued Suppose that we have iid Ber.pdf
742 Example 743 Continued Suppose that we have iid Ber.pdf
access2future1
 
Holt Enterprises recently paid a dividend D0 of 275 It .pdf
Holt Enterprises recently paid a dividend D0 of 275 It .pdfHolt Enterprises recently paid a dividend D0 of 275 It .pdf
Holt Enterprises recently paid a dividend D0 of 275 It .pdf
access2future1
 
i am trying to add the first four lines of a studenttxt int.pdf
i am trying to add the first four lines of a studenttxt int.pdfi am trying to add the first four lines of a studenttxt int.pdf
i am trying to add the first four lines of a studenttxt int.pdf
access2future1
 
2 Use the information above to complete the Aging of Accoun.pdf
2 Use the information above to complete the Aging of Accoun.pdf2 Use the information above to complete the Aging of Accoun.pdf
2 Use the information above to complete the Aging of Accoun.pdf
access2future1
 

More from access2future1 (20)

The following stockholders equity accounts arranged alphabe.pdf
The following stockholders equity accounts arranged alphabe.pdfThe following stockholders equity accounts arranged alphabe.pdf
The following stockholders equity accounts arranged alphabe.pdf
 
You are considering a stock investment in one of two firms .pdf
You are considering a stock investment in one of two firms .pdfYou are considering a stock investment in one of two firms .pdf
You are considering a stock investment in one of two firms .pdf
 
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdfThe Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
 
Second Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdfSecond Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdf
 
Researchers found that a person in a particular country spen.pdf
Researchers found that a person in a particular country spen.pdfResearchers found that a person in a particular country spen.pdf
Researchers found that a person in a particular country spen.pdf
 
QUESTION 2 internal rate of return method 14 RETURN USE N.pdf
QUESTION 2 internal rate of return method 14 RETURN  USE N.pdfQUESTION 2 internal rate of return method 14 RETURN  USE N.pdf
QUESTION 2 internal rate of return method 14 RETURN USE N.pdf
 
Question 17 Which of the following contributes directly to t.pdf
Question 17 Which of the following contributes directly to t.pdfQuestion 17 Which of the following contributes directly to t.pdf
Question 17 Which of the following contributes directly to t.pdf
 
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdfProporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
 
Please Use SWISH and write the code answer each part carefu.pdf
Please Use SWISH and write the code answer each part carefu.pdfPlease Use SWISH and write the code answer each part carefu.pdf
Please Use SWISH and write the code answer each part carefu.pdf
 
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdfPLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
 
please help with the fill in the blanks Fill in the followin.pdf
please help with the fill in the blanks Fill in the followin.pdfplease help with the fill in the blanks Fill in the followin.pdf
please help with the fill in the blanks Fill in the followin.pdf
 
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdfPatient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
 
Please fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdfPlease fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdf
 
Name the hormones that influence the menstrual cycle Ident.pdf
Name the hormones that influence the menstrual cycle  Ident.pdfName the hormones that influence the menstrual cycle  Ident.pdf
Name the hormones that influence the menstrual cycle Ident.pdf
 
Mike and Carol Brady realized that their house was not big e.pdf
Mike and Carol Brady realized that their house was not big e.pdfMike and Carol Brady realized that their house was not big e.pdf
Mike and Carol Brady realized that their house was not big e.pdf
 
Debugging C Console Program Debug the program to identify .pdf
Debugging C Console Program Debug the program to identify .pdfDebugging C Console Program Debug the program to identify .pdf
Debugging C Console Program Debug the program to identify .pdf
 
742 Example 743 Continued Suppose that we have iid Ber.pdf
742 Example 743 Continued Suppose that we have iid Ber.pdf742 Example 743 Continued Suppose that we have iid Ber.pdf
742 Example 743 Continued Suppose that we have iid Ber.pdf
 
Holt Enterprises recently paid a dividend D0 of 275 It .pdf
Holt Enterprises recently paid a dividend D0 of 275 It .pdfHolt Enterprises recently paid a dividend D0 of 275 It .pdf
Holt Enterprises recently paid a dividend D0 of 275 It .pdf
 
i am trying to add the first four lines of a studenttxt int.pdf
i am trying to add the first four lines of a studenttxt int.pdfi am trying to add the first four lines of a studenttxt int.pdf
i am trying to add the first four lines of a studenttxt int.pdf
 
2 Use the information above to complete the Aging of Accoun.pdf
2 Use the information above to complete the Aging of Accoun.pdf2 Use the information above to complete the Aging of Accoun.pdf
2 Use the information above to complete the Aging of Accoun.pdf
 

Recently uploaded

special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 

Recently uploaded (20)

special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 

output and explain There is Mylist There is MyArrayList pa.pdf

  • 1. output and explain There is Mylist; There is MyArrayList: package com.mycompany.myarraylist; import java.util.*; public class MyArrayList<E> implements MyList<E> { private class ArrayListIterator implements Iterator<E> { private int index; public ArrayListIterator() { index=0; } public boolean hasNext() { return index < size(); } public E next() { index++; return arr[index-1]; } public void remove() { throw new UnsupportedOperationException(); } } private E[] arr; private int logicalLength; public MyArrayList(int initCapacity) { arr = (E[]) new Object[initCapacity]; logicalLength = 0; } public MyArrayList() { this(4); } public boolean add(E e) { if(isFull()) grow();
  • 2. arr[logicalLength] = e; logicalLength++; return true; } public void add(int index, E element) { if(isOutOfBounds(index)) throw new IndexOutOfBoundsException(index + " doesn't exist"); if(isFull()) grow(); for(int i=size()-1; i>=index; i--) arr[i+1] = arr[i]; arr[index] = element; logicalLength++; } public void clear() { logicalLength = 0; } public boolean contains(Object obj) { return indexOf(obj) != -1; } public boolean equals(Object obj) { if(!(obj instanceof MyArrayList)) return false; MyArrayList<E> another = (MyArrayList<E>)obj; if(size() != another.size()) return false; for(int i=0; i<size(); i++) if(! (arr[i].equals(another.arr[i]))) return false; return true; } public E get(int index) { if(isOutOfBounds(index))
  • 3. throw new IndexOutOfBoundsException(index + " doesn't exist"); return arr[index]; } public E set(int index, E element) { if(isOutOfBounds(index)) throw new IndexOutOfBoundsException(index + " doesn't exist"); E answer = arr[index]; arr[index] = element; return answer; } public int indexOf(Object obj) { for(int i=0; i<size(); i++) if(arr[i].equals(obj)) return i; return -1; } public boolean isEmpty() { return size()==0; } public int size() { return logicalLength; } public Iterator<E> iterator() { return new ArrayListIterator(); } public int lastIndexOf(Object obj) { for(int i=size()-1; i>=0; i--) if(arr[i].equals(obj)) return i; return -1; }
  • 4. public E remove(int index) { if(isOutOfBounds(index)) throw new IndexOutOfBoundsException(index + " doesn't exist"); E data = arr[index]; for(int i=index+1; i<size(); i++) arr[i-1] = arr[i]; logicalLength--; return data; } public boolean remove(Object obj) { int index = indexOf(obj); if(index==-1) return false; remove(index); return true; } public String toString() { StringBuilder sb = new StringBuilder("[ "); for(int i=0; i<logicalLength; i++) { sb.append(arr[i]); if(i < logicalLength-1) sb.append(", "); } sb.append("]"); return sb.toString(); } private void grow() { int newCapacity = 2 * arr.length; E[] temp = (E[]) new Object[newCapacity]; for(int i=0; i<logicalLength; i++) temp[i] = arr[i]; arr = temp; }
  • 5. private boolean isFull() { return logicalLength == arr.length; } private boolean isOutOfBounds(int index) { return index<0 || index>=logicalLength; } public static void main(String[] args) { MyArrayList<Integer> list = new MyArrayList<Integer>(); for(int i=0; i<10; i++) list.add(i+10); for(Iterator<Integer> it = list.iterator(); it.hasNext(); ) { System.out.println(it.next()); } for(int x: list) System.out.println(x); System.out.println(list); list.remove((Integer)10); System.out.println(list); } }