我有以下代碼:如何根據條件找到未找到映射中的鍵的邏輯?
for(String s1 : source){
for(String s2 : target){
if(s1.length() > 4 && s2.length() > 4){
String sKey = s1.substring(1,5);
String tKey = s2.substring(1,5);
if(sKey.equals(tKey)){
//Do your logic...
}else if(!sKey.equals(tKey) && sKey not availlable in the target list){
//print the value that sKey not availlable in target
}
}
}
}
我需要打印的值,如果鍵沒有整個清單的完整穿越找到。
請幫忙!!
你能解釋你到底想要達到什麼嗎? – Mureinik
如果密鑰在第二個列表中不可用,那麼我必須打印此密鑰在目標/第二個列表中不可用,反之亦然。 – vermaraj
這是一個列表還是地圖,還是你有每一個?您的標題說'地圖',但您的for循環不會將'source'和'target'視爲地圖,並且您的文本顯示「遍歷列表」。 「目標」是「列表」嗎? –