我需要一个导航地图转换为2D字符串array.Below给出的是从answer代码我刚才的问题之一。如何将NavigableMap的转换为String [] []
NavigableMap<Integer,String> map =
new TreeMap<Integer, String>();
map.put(0, "Kid");
map.put(11, "Teens");
map.put(20, "Twenties");
map.put(30, "Thirties");
map.put(40, "Forties");
map.put(50, "Senior");
map.put(100, "OMG OMG OMG!");
System.out.println(map.get(map.floorKey(13))); // Teens
System.out.println(map.get(map.floorKey(29))); // Twenties
System.out.println(map.get(map.floorKey(30))); // Thirties
System.out.println(map.floorEntry(42).getValue()); // Forties
System.out.println(map.get(map.floorKey(666))); // OMG OMG OMG!
我有这个地图转换为二维String数组:
{
{"0-11","Kids"},
{"11-20","Teens"},
{"20-30","Twenties"}
...
}
是否有一个快速和优雅的方式来做到这一点?
' “妈呀妈呀妈呀!”“ - LOL难怪片段看起来很熟悉... – polygenelubricants 2010-08-26 11:45:48
@poly:有一个更好的解决方案? – Emil 2010-08-26 11:48:14
@Emil:你是否必须将数据表示为一个String [] []'?怎么样一个普通的'List>'而不是?你可以得到'MappedInterval.start()'和'.END()'和'.value的()',你可以'@ Override'的'的toString()'打印像'[开始结束] = >价值'或类似的东西。基本上我不认为你可以想出任何更好的算法来转换为'String [] []',但是比起'String [] []'有更好的表示,我可以给出这个片段要做到这一点。 –
polygenelubricants
2010-08-26 11:54:29