Given the following class declaration, write the code in Java for the add function: public class
ArrayList {Private Object []a; Public ArrayList() {a = new Object[10];} public ArrayList(int n)
{a = new Object[n];} public int size() {if[a[0] = = null) return 0; else {int I = 0, count = 0;
while(a[i]! = null){count ++; i++} return count;} public void add(Object n) {
Solution
public void add(Object n)
{
int count = size();
if(count != 0)
{
a[count++] = n; // add the object n to a
}
}

Given the following class declaration- write the code in Java for the.docx

  • 1.
    Given the followingclass declaration, write the code in Java for the add function: public class ArrayList {Private Object []a; Public ArrayList() {a = new Object[10];} public ArrayList(int n) {a = new Object[n];} public int size() {if[a[0] = = null) return 0; else {int I = 0, count = 0; while(a[i]! = null){count ++; i++} return count;} public void add(Object n) { Solution public void add(Object n) { int count = size(); if(count != 0) { a[count++] = n; // add the object n to a } }