我想將我的玩家的位置保存到一個列表中,這項工作很好,但現在如何通過搜索玩家名稱的列表來獲取我的位置?在其中創建列表類的代碼Java從列表中獲取整數和字符串的字符串
片和列表
public static class Character {
private String name;
private Location location;
public Character(String name, Location location) {
this.name = name;
this.location = location;
}
}
public static class Location {
private int x;
private int y;
private int z;
public Location(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
List<Character> rawInput = new ArrayList<Character>();
一段代碼,我的項目添加到列表:
else if (args[0].equalsIgnoreCase("select"))
{
int tmpX = (int)player.getLocation().getX();
int tmpY = (int)player.getLocation().getY();
int tmpZ = (int)player.getLocation().getZ();
rawInput.add(
new Character(player.getName(), new Location(tmpX, tmpY, tmpZ)));
player.sendMessage(
ChatColor.GOLD + "[PlusCommands] " + ChatColor.GREEN
+ "selected location set to player location!");
}
這工作都很好,但我該怎麼辦獲取數據返回例如:
這是一個位置列表:玩家名稱XYZ:
PlayerThree 32 13 46
PlayerTwo 12 60 212
PlayerOne 43 62 523
所以我要搜索在該示例情況下,右側玩家我PlayerOne 因此,我想從數據其中字符串表示PlayerOne
在這種情況下,playerList那這一個:PlayerOne 43 62 523
如何做到這一點???
我希望我很清楚,如果沒有抱歉。
在你的課堂上添加一個getter方法? – noMAD
@noMAD getter方法? –
'公共靜態位置getLocation(字符串名稱){//做東西來檢查名稱是否可用//獲取特定於名稱返回位置的位置; }' – noMAD