SlideShare a Scribd company logo
1 of 5
Download to read offline
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. StreamsDEVTYPE
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magenvenaymagen19
 
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.pdfsales88
 
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.pdfcronkwurphyb44502
 
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.pdfankit482504
 
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.pdfakkhan101
 
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.pdfStewart29UReesa
 
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 APIjagriti 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.pdfabbecindia
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxhemanth248901
 
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 2018Codemotion
 
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.pdfannaelctronics
 
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.pdfmohamednihalshahru
 
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.pdfinfo430661
 
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.pdfsyedabdul78662
 
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.docxStewartt0kJohnstonh
 
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.docxGavinUJtMathist
 

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.pdfaccess2future1
 
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 .pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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 .pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 
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 .pdfaccess2future1
 
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.pdfaccess2future1
 
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 .pdfaccess2future1
 
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.pdfaccess2future1
 
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.pdfaccess2future1
 

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

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
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
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
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 

Recently uploaded (20)

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
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.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 ...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
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
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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 🔝✔️✔️
 
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
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
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🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
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🔝
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 

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); } }