简体   繁体   中英

“Attach” an integer to a string array, Java

I'm trying to have a hidden integer value attached to each string in this array.

String[] playerArray = {"Player1"};

For example, I want to be able to input "Player1, 44 28 63", and have those integers hidden, but able to act on it's own.

I think what you want to do is create a Player object and have an array of those:

class Player {
   private String name; //?
   private int int1; //?

   public Player(String name, int int1) {
       this.name = name;
       this.in1 = int1;
   }
}

Player[] players = new Player[] {new Player("My String", 42);}

The good thing about this class is, that you can place code, methods, who acts on this data inside the class and so it helps your organize your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM