示例
我想比较SDK编号和一个值,并显示值的名称,例如sdk 25 = nougat
字符串sdks = Build.VERSION.SDK;
int Alpha = 1;
int Beta = 2;
int CupCake = 3;
int Donut = 4;
int Eclair= 5-7;
int Froyo = 8;
int GingerBread = 9-10;
int HoneyComb = 11-13;
int IceCreamSandwich = 14-15;
int JellyBean = 16-18;
int KitKat = 19-20;
int Lollipop = 21-22;
int MarshMellow = 23;
int Nougat = 24-25;
int Oreo = 26-27;
int Pie = 28;
resultview.setText(sdks);
答案 0 :(得分:0)
我认为,鉴于地图解决方案的范围较小,因此它的实现很简单
public static void main(String []args){
Map<Integer,String> sdkMap = new HashMap<Integer,String>();
//populate other fields similarly
HelloWorld.populateRange("24-25","Nougat",sdkMap);
System.out.println(sdkMap.get(24));
}
public static void populateRange(String range,String name, Map<Integer,String> sdkMap){
String[] splitNumbers = range.split("-");
int low = Integer.parseInt(splitNumbers[0]);
int high = Integer.parseInt(splitNumbers[1]);
for(int i=low;i<=high;i++){
sdkMap.put(i,name);
}
}