...
Code Block | ||
---|---|---|
| ||
class BankOperations { private static void removeAccounts(Vector v, String name) { Enumeration e = v.elements(); while (e.hasMoreElements()) { String s = (String) e.nextElement(); if (s.equals(name)) { v.remove("Harry"name); // Second Harry is not removed } } // Display current account holders System.out.println("The names are:"); e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); // Prints Dick, Harry, Tom } } public static void main(String args[]) { // List contains a sorted array of account holder names // Repeats are admissible List list = new ArrayList(Arrays.asList( new String[] {"Dick", "Harry", "Harry", "Tom"})); Vector v = new Vector(list); removeAccount(v, "Harry"); } } |
...