Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a hashmap & its values from other class in java?

I would like to create 5-6 classes,I am storing values in hashmap in 1st class & I would like to call it from 4th,5th & 6th class.How to get this any snippets or example to implement this will be helpful,Thanks

like image 541
Karthik Avatar asked Jan 04 '12 06:01

Karthik


1 Answers

public class Example {

    private HashMap<String, String> hashmap = new HashMap<String, String>();

    public HashMap<String, String> getHashmap() {
        return hashmap;
    }

    public void setHashmap(HashMap<String, String> hashmap) {
        this.hashmap = hashmap;
    }
}

public class AnotherClass {

    public static void main(String args[]) {
        Example ex = new Example();
        HashMap<String, String> hm = ex.getHashmap();
    } 

}
like image 121
Kimi Avatar answered Oct 04 '22 15:10

Kimi