【发布时间】:2012-01-25 00:11:05
【问题描述】:
我得到一个对象作为参数,并想将对象的键与字符串数组进行比较。
对象的类型为Map <String, byte[]>
String [] keys = {"a", "b"}
抱歉缺席,我没有机会来这里,所以我会尽力解释我想要什么。我通过套接字接收一个对象,然后通过对象参数传递给方法readObject。
Map 在这种方法中,我必须将“K”(键)分开并将它们插入到不同的 Map 中。例如:
Map 1 (String [] = {1 map "a", "f", "c", "d"};
Map 2 (String [] {map = 2 "and", "i", "o", "k"};
main class
{ //...
S.getInputStream InputStream is =..... ();
ObjectInputStream ois = new ......;
MapObject mo = (MapObject) ois.readObject ();
//-----> ReadObject (mo)
... }
public static MapObject readObject (MapObject mo) {
String [] map1 = { "a", "f", "c", "d"};
有可能吗? ----> MapObject mapi = mo;
他在下一步爆发
这------->
Map map = (Map ) mo;
for (Map.Entry entry : map.entrySet ()) {
Entry.getKey key = String ();
byte [] value = entry.getValue ();
if (test.equals (entry.getKey ()))
{
map.put (key, value);
}
}
}
public void readObject(Object parObj)
{
Here I want to extract the key from parObj comparable to do with the String []
for example an if ().
finally extract unable to insert a value to put (Key, Value);
}
我的难点在于提取key和value。
实现我的目标的一些建议或提示?
感谢您的关注和有空
【问题讨论】:
-
为什么不直接把参数的类型改成
Map<String, byte[]>? -
我得解释一下。我需要传递套接字对象,然后使用将字符串和值作为参数的 put 方法。
-
您需要提供更多细节并更好地解释它。到目前为止的帖子真的很混乱。
-
@Jeffrey:我猜
java.io.Serializable在这里起了作用。 -
@BalusC 这就是我的想法,但由于 OP 从未真正说过,我不想做出错误的假设。