Java Write Dupend Method Duplicates Last Item Arraylist Tester Dupend Public Class Arrayli Q37031251

java

write dupEnd method, that duplicates the last item in thearraylist.

the tester for the dupEnd is below

public class ArrayList<T>
{
private Object[] myArray; // array of list entries
private int mySize;
private static final int DEFAULT_INITIAL_CAPACITY = 25;

// public methods:
public ArrayList()
{
this(DEFAULT_INITIAL_CAPACITY);
} // end default constructor

public ArrayList(int initialCapacity)
{
mySize = 0;   
myArray = new Object[initialCapacity];
} // end constructor
  
  
public void add(Object newEntry)
{
myArray[mySize] = newEntry;
mySize++;
} // end add

/** Converts all the data in the bag into one big String
@return a very long String of objects contained in bag */
public String toString()
{   
int k;
String result = “”;
for (k=0; k<mySize; k++)
if (k<mySize-1)
result += myArray[k] + “, “; // up to item

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.