我有这样的地图:
(def my-map {43423 43.3, 63452 32.02, 823828 67.43, ...})
Run Code Online (Sandbox Code Playgroud)
以及不同顺序的键向量:
(def my-keys [63452 823828 43423 ...])
Run Code Online (Sandbox Code Playgroud)
如何在my-map上调用my-keys向量来提取值并保持向量的顺序,如下所示?
;=> [32.02 67.43 43.3 ...]
Run Code Online (Sandbox Code Playgroud)
只要维护订单,返回的任何数据类型都可以.
我正在使用GNU Make编译我的Java项目,它不支持泛型.
这是我的小代码导致错误:
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) > 127) {
buffer.append("\"");
String charValue = asciiToNascMap.get(String.valueOf((int)text.charAt(i)));
buffer.append(String.format(";CHR$(%d);\"", charValue));
} else {
buffer.append(text.charAt(i));
}
}
private static Map<String, String> asciiToNascMap = new HashMap<String, String>();
static {
asciiToNascMap.put("232", "125");//è
asciiToNascMap.put("233", "123");//é
asciiToNascMap.put("224", "64");//à
asciiToNascMap.put("231", "92");//ç
asciiToNascMap.put("199", "180");//Ç
asciiToNascMap.put("234", "193");//ê
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Printer.java:319: error:Cannot find method "java/lang/String.format(java.lang.String, java.lang.String)"
Run Code Online (Sandbox Code Playgroud)
这是String.format方法的签名:
/**
* Returns a formatted string using the specified format string and
* arguments.
*
* <p> …Run Code Online (Sandbox Code Playgroud) 我需要从Hazelcast分布式地图中删除一个项目,我使用类似这样的代码(简化):
public void realeaseBatchesById(int Id) {
Iterator<Map.Entry<Long, WorkingBatch>> it = workingMap.entrySet().iterator();
while (it.hasNext()) {
WorkingBatch value = it.next().getValue();
if (value.getServer().getId() == idd) {
it.remove();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码不会删除值,地图的大小在开头与结尾处的大小相同.
当我看到Hazelcast Javadoc时,我看到这个接口只定义了按键和键的值删除.这是否意味着我不能使用标准方法如何从地图中删除值?
我试图获取整数列表并重复多次,但作为haskell中的字符串.预期的产出是:
> nnn [3,1,5] = ["3-3-3","1","5-5-5-5-5"]
> nnn [10,2,4] = ["10-10-10-10-10-10-10-10-10-10","2-2","4-4-4-4"]
Run Code Online (Sandbox Code Playgroud)
现在我觉得我很接近......但是我不能把一个int列表变成一个String,并且肯定不知道如何处理连字符.这是我到目前为止的代码,并输出:
nnn :: [Int] -> [[Char]]
nnn list = map show (map (\x -> take x $ repeat x) list)
Run Code Online (Sandbox Code Playgroud)
它给了我:
> nnn [3,1,5] = ["[3,3,3]","[1]","[5,5,5,5,5]"]
Run Code Online (Sandbox Code Playgroud)
(我至少接近!)有人能指出我正确的方向来看这里吗?:)
我想迭代Map,其中值是另一个Map.我有这个方法:
public void test(){
Map<Integer, Double> map1 = new HashMap<Integer, Double>();
Map<Integer, Map<Integer, Double>> map2 = new HashMap<Integer, Map<Integer, Double>>();
map1.put(1,1.1);
map1.put(2,2.2);
map1.put(3,3.3);
map2.put(1,map1);
map1.clear();
map1.put(4,4.4);
map1.put(5,5.5);
map1.put(6,6.6);
map2.put(2,map1);
for (Map.Entry<Integer, Map<Integer, Double>> entry : map2.entrySet()){
Log.d("test", "map2 key " + entry.getKey());
Map<Integer, Double> tempMap = new HashMap<Integer, Double>(entry.getValue());
for (Map.Entry<Integer, Double> entry1 : tempMap.entrySet()){
Log.d("map", "map1 key " + entry1.getKey() + "map1 value " + entry1.getValue());
}
}
Run Code Online (Sandbox Code Playgroud)
我在日志中看到这个:
map2 key 1
map1 key 4 map1 value 4.4
map1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将元素插入到可变的Map中,并且在我尝试的时候,我得到了如下异常:
java.lang.ArrayIndexOutOfBoundsException: 62388
at scala.collection.mutable.HashTable$class.resize(HashTable.scala:255)
at scala.collection.mutable.HashTable$class.scala$collection$mutable$HashTable$$addEntry0(HashTable.scala:151)
at scala.collection.mutable.HashTable$class.findOrAddEntry(HashTable.scala:163)
at scala.collection.mutable.HashMap.findOrAddEntry(HashMap.scala:39)
at scala.collection.mutable.HashMap.$plus$eq(HashMap.scala:89)
at scala.collection.mutable.HashMap.$plus$eq(HashMap.scala:39)
at test.testMethod(AkkaLoadTest.scala:165)
at test.testMethod(AkkaLoadTest.scala:27)
at rait$PriceRequestWorker$$anonfun$receive$2.applyOrElse(AkkaLoadTest.scala:224)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
at akka.actor.ActorCell.invoke(ActorCell.scala:386)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
at akka.dispatch.Mailbox.run(Mailbox.scala:212)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Run Code Online (Sandbox Code Playgroud)
它看起来很奇怪!这是我做的:
var mutableMap= scala.collection.mutable.Map[String, List[String]]()
Run Code Online (Sandbox Code Playgroud)
我在我的对象和testMethod中全局声明了Map,我执行以下操作:
if(anotherList.size > 0) {
mutableMap.get(id) match {
case Some(entries) => /* Do nothing as the entry is already available in the map */
case None => {
mutableMap+= id-> anotherList
}
}
}
Run Code Online (Sandbox Code Playgroud)
id作为另一个参数传递给实现上述代码的方法.我很困惑地看到在我看来根本不相关的例外!有任何想法吗?
如何将地图转换为列表而不在scala中的列表中包含映射键?
val mp = collection.mutable.Map[Long, String]()
mp(0) = "val0"
mp(1) = "val1"
mp(2) = "val2"
mp.toList //I want: List("val0", "val1", "val2")
Run Code Online (Sandbox Code Playgroud) 我有一张这样的地图
Key: 9970DLXEVOQ0O Value: [{9972IOFNIDER6 0.3},{9972MFYWYJIEK 0.2},{9972QIUUINW6R 0.5}]
Key: 9970DLXEVOQ01 Value: [{9972IOFNIDER6 0.3}]
Key: 9970QYPOYUUIO Value: [{9972VOFA3OJLK 0.4}]
Run Code Online (Sandbox Code Playgroud)
在golang中命名为product_deal,其中key是string,value是struct:
type product_detail struct {
deal_id string
rating float64
}
Run Code Online (Sandbox Code Playgroud)
我需要根据输出应该是的每个值字段中的评级(降序)对值进行排序
Key: 9970DLXEVOQ0O Value: [{9972QIUUINW6R 0.5},{9972IOFNIDER6 0.3},{9972MFYWYJIEK 0.2}]
Key: 9970DLXEVOQ01 Value: [{9972IOFNIDER6 0.3}]
Key: 9970QYPOYUUIO Value: [{9972VOFA3OJLK 0.4}]
Run Code Online (Sandbox Code Playgroud)
关于如何做到这一点的任何想法.我确实看过其他帖子哪个排序地图但无法获得实施.任何帮助,将不胜感激.
如何从`Map中提取整数数组的长度?
Map <Integer, ArrayList<Integer>> res = function() ;
for (Map.Entry entry : res.entrySet()) {
System.out.println(entry.getValue());
}
Run Code Online (Sandbox Code Playgroud)
做System.out.println(entry.getValue().size());不起作用.
applyAll :: [[a] -> [a]] -> [a] -> [a]
applyAll [] [] = []
applyAll [] a = a
applyAll (f1:fl) a = applyAll( (drop 1 fl)(f1 a))
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
Expression : drop 1 fl (f1 a)
Term : drop
Type : Int -> [e] -> [e]
Does not match : a -> b -> c -> d
Run Code Online (Sandbox Code Playgroud)
我想做那样的事
applyAll [tail, tail, tail, tail] [1,2,3,4,5] = [5],
applyAll [(map (* 2)), (map (+ 1))] [1,2,3,4,5]) = [3,5,7,9,11]
Run Code Online (Sandbox Code Playgroud)