File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes setting value of map from another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting value of map from another class" Watch "setting value of map from another class" New topic
Author

setting value of map from another class

kamesh aru
Ranch Hand

Joined: Mar 16, 2002
Posts: 150
i have a class containg map with values set.
i want to change this values from another class.

here is the class with map
public class Status {


private static Map map = new HashMap();
Status(){
map.put("abc","true");
map.put("cfv","true");
map.put("vgf","true");
map.put("vfg","true");


}






/**
* @return
*/
public static Map getMap() {
return map;
}

/**
* @param map
*/
public static void setMap(Map map) {
Status.map = map;
}

}
i need to set the value of this map in other class can any one help me out
thanks in advance
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
What do you mean change the value of this map from another class?

You have a getMap method so you can use that. Since it is static you setMap should synchronize:

public void setMap(Map map) { Status.map = Collections.synchronizedMap(map); }

You must make sure you only use the reference returned by getMap to manipulate the map.
 
GeeCON Prague 2014
 
subject: setting value of map from another class