









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Stack
Set
set
Java Collections
ArrayList
import java.util.ArrayList;
ArrayList
import java.util.ArrayList; public class Test { public static void main(String[] args) { ArrayList
int i; // First add 4 numbers to the arraylist for (i=0; i<4; i++) { v.add(new MyIntClass(i)); } // Print out size of the arraylist, should be 4 System.out.println("Size: " + v.size() + "\n"); // Print arraylist System.out.println("Original arraylist:"); PrintArraylist(v); // Remove the second element v.remove(2); // Print out the elements again System.out.println("After remove:"); PrintArraylist(v); // Insert the number 100 at position 1 v.add(1, new MyIntClass(100)); // Print out the elements again System.out.println("After insert:"); PrintArraylist(v); } // This method prints out the elements in the arraylist public static void PrintArraylist(ArrayList
// Index of - System.out.println("Position of 1"); System.out.println(v.indexOf(new MyIntClass(1)));
Position of 1
public boolean equals(Object otherIntObject) { MyIntClass otherInt = (MyIntClass) otherIntObject; if (this.m_value == otherInt.m_value) return true; return false; }
Position of 1 2
// This method prints out the elements in the arraylist public static void PrintArraylist(ArrayList
Map and HashMap