我遇到了一些包含一个有趣的“数据结构”的javascript(我不太确定这是不是真的是这样)。
myApp.controller('MyCtrl', ['$scope', function($scope) {
var dustToLevel = [
{"dust":200, "candy":1, "pkmnLevel": [1, 1.5, 2, 2.5]},
{"dust":400, "candy":1, "pkmnLevel": [3, 3.5, 4, 4.5]},
{"dust":600, "candy":1, "pkmnLevel": [5, 5.5, 6, 6.5]},
{"dust":800, "candy":1, "pkmnLevel": [7, 7.5, 8, 8.5]},
{"dust":1000, "candy":1, "pkmnLevel": [9, 9.5, 10, 10.5]},
{"dust":1300, "candy":2, "pkmnLevel": [11, 11.5, 12, 12.5]},
{"dust":1600, "candy":2, "pkmnLevel": [13, 13.5, 14, 14.5]},
{"dust":1900, "candy":2, "pkmnLevel": [15, 15.5, 16, 16.5]},
{"dust":2200, "candy":2, "pkmnLevel": [17, 17.5, 18, 18.5]},
{"dust":2500, "candy":2, "pkmnLevel": [19, 19.5, 20, 20.5]},
{"dust":3000, "candy":3, "pkmnLevel": [21, 21.5, 22, 22.5]},
{"dust":3500, "candy":3, "pkmnLevel": [23, 23.5, 24, 24.5]},
{"dust":4000, "candy":3, "pkmnLevel": [25, 25.5, 26, 26.5]},
{"dust":4500, "candy":3, "pkmnLevel": [27, 27.5, 28, 28.5]},
{"dust":5000, "candy":3, "pkmnLevel": [29, 29.5, 30, 30.5]},
{"dust":6000, "candy":4, "pkmnLevel": [31, 31.5, 32, 32.5]},
{"dust":7000, "candy":4, "pkmnLevel": [33, 33.5, 34, 34.5]},
{"dust":8000, "candy":4, "pkmnLevel": [35, 35.5, 36, 36.5]},
{"dust":9000, "candy":4, "pkmnLevel": [37, 37.5, 38, 38.5]},
{"dust":10000, "candy":4, "pkmnLevel": [39, 39.5, 40, 40.5]} ];
我很好奇是否有可以在java中使用的等价物。或者像hashmap这样的东西,允许我将多个值与一个键相关联。
对于这个问题的答案,我看起来更多,而不是为什么我应该已经知道答案的原因,谢谢。
答案 0 :(得分:2)
我建议你为结构创建一个类:
public class DustToLevel
{
public DustToLevel(int dust, int candy, float[] pkmnLevel)
{
this.dust = dust;
this.candy = candy;
this.pkmnLevel = pkmnLevel;
}
public int dust;
public int candy;
public float[] pkmnLevel;
}
您的实施将会:
List<DustToLevel> dustToLevels = new ArrayList<DustToLevel>();
dustToLevels.Add(new DustToLevel(200, 1, new float[] {1.5f, 2.0f, 3.5f}));
答案 1 :(得分:1)
我会创建一个包含所需信息的类:
EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: ''
然后,您将创建一个类的实例列表。 通常你会使用ArrayList实现。