java - How do I use a HashMap from another class or function? -


here working code example. @markspace providing me it. code here makes hashmap , inserts values in it.

 public class rpgpersonexample {    public static void main( string[] args )    {       map<string, rpgperson> team = new hashmap<>();       team.put( "sgt. mayhem", new rpgperson( 100, 10, 0 ) );       team.put( "wizard", new rpgperson( 100, 1, 10 ) );       team.put( "dragon", new rpgperson( 1000, 100, 100 ) );        system.out.println( team.get( "dragon" ) );       system.out.println( team.get( "wizard" ) );    }  }  class rpgperson {     private int hits;    private int strength;    private int magic;     public rpgperson( int hits, int strength, int magic )    {       this.hits = hits;       this.strength = strength;       this.magic = magic;    }     @override    public string tostring()    {       return "rpgperson{" + "hits=" + hits + ", strength=" +               strength + ", magic=" + magic + '}';    }  } 

what want though use class. if use

       system.out.println( team.get( "dragon" ) ); 

from main function works fine. how should i want class?

public class test {      public static void example(){          system.out.println( rpgperson.team.get( "dragon" ) );      } } 

the class test not work should if want work?

the simplest thing can pass example method argument references map:

 public static void example(map<string, rpgperson> team) {      system.out.println(team.get("dragon"));  } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -