got another issue.
Im trying to send an entire Map of objects and their associated keys so that it can be accessed from another class. The method I am using does not work, as I tried to use the same method that is used to pass an array list, but it does not work for a Map.
what would be the correct way of doing it?
this is what I have tried
public Map <Integer, Employee> getAllEmps()
{
return (Map <Integer, Employee>) ;
}
and this is how I have declared it (the actual map itself)
private static Map <Integer, Employee> employeeMap = new TreeMap<Integer,Employee>();
You can return the variable itself:
Which would allow anyone to modify the contnent of the map.
To prevent modification, you can return an unmodifiableMap:
Alternatively, you can return a copy: