import java.util.*;
public class MapTest
{ public static void main(String[] args)
{ Map staff = new HashMap();
staff.put("144-25-5464", new Employee("Angela Hung"));
staff.put("567-24-2546", new Employee("Harry Hacker"));
staff.put("157-62-7935", new Employee("Gary Cooper"));
staff.put("456-62-5527", new Employee("Francesca Cruz"));
// print all entries
System.out.println(staff);
// remove an entry
staff.remove("567-24-2546");
// replace an entry
staff.put("456-62-5527", new Employee("Francesca Miller"));
// look up a value
System.out.println(staff.get("157-62-7935"));
// iterate through all entries
Set entries = staff.entrySet();
Iterator iter = entries.iterator();
while (iter.hasNext())
{ Map.Entry entry = (Map.Entry)iter.next();
Object key = entry.getKey();
Object value = entry.getValue();
System.out.println("key=" + key + ", value=" + value);
}
}
}
class Employee
{ public Employee(String n)
{ name = n;
salary = 0;
}
public String toString()
{ return "[name=" + name + ", salary=" + salary + "]";
}
public void setSalary(double s)
{ salary = s;
}
private String name;
private double salary;
}
6/26/10
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Hi folks, I got a chance to work with JSF, it was an interesting requirement. Its about a custom component which would be of more use to ...
-
Hi Folks, I would like to share my another POC task in JSF with you all. "Primefaces Dropdown with Pagination & Filter "...
-
We shall create temp table in mysql using the sql script CREATE TEMPORARY TABLE testraghu(name VARCHAR(50) , phone VARCHAR(50)) Let us se...
-
Hi all, i would like to share a simple example of storing haspmap in mysql db. In order to store object into your db, the field type must ...
No comments:
Post a Comment