當前位置: 首頁>>代碼示例>>Java>>正文


Java HashMap.replace方法代碼示例

本文整理匯總了Java中java.util.HashMap.replace方法的典型用法代碼示例。如果您正苦於以下問題:Java HashMap.replace方法的具體用法?Java HashMap.replace怎麽用?Java HashMap.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.HashMap的用法示例。


在下文中一共展示了HashMap.replace方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.util.HashMap; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner scanner=new Scanner(System.in);
    HashMap<String, Integer> map = new HashMap<String, Integer>(16);
    map.put("he",98);
    map.put("he1",99);
    map.put("he",100);
    map.replace("he",1000);
    System.out.println(map.entrySet());
    System.out.println(map.get("he"));
}
 
開發者ID:Philippian,項目名稱:PatProject,代碼行數:11,代碼來源:Test3Hashmap.java

示例2: deleteDoubleMacFromDataBase

import java.util.HashMap; //導入方法依賴的package包/類
/**
 * delete double mac from database
 * @param database
 */
public static void deleteDoubleMacFromDataBase(Vector<sameScanWifi> dataBase){
	HashMap< String,sameScanWifi> hmap = new HashMap< String,sameScanWifi>();
	for (Iterator<sameScanWifi> sameScanWifiIterator = dataBase.iterator(); sameScanWifiIterator.hasNext(); ) {
		sameScanWifi currentSameScanWifi=sameScanWifiIterator.next();
		for(Iterator<wifi> iter = currentSameScanWifi.iterator(); iter.hasNext(); ) {
			wifi currentWifi=iter.next();
			if(hmap.get(currentWifi.getMAC())==null){
				hmap.put(currentWifi.getMAC(), currentSameScanWifi);
			}
			else{
				for(wifi sameMac:hmap.get(currentWifi.getMAC())){
					if(sameMac.getMAC().equals(currentWifi.getMAC())){
						if(sameMac.getRSSI()>currentWifi.getRSSI()){
							iter.remove();
							break;
						}
						else{
							hmap.get(currentWifi.getMAC()).remove(sameMac);
							hmap.replace(currentWifi.getMAC(),  currentSameScanWifi);
						}
					}
				}
			}
		}
	}
	for (Iterator<sameScanWifi> sameScanWifiIterator = dataBase.iterator(); sameScanWifiIterator.hasNext(); ) {
		if(sameScanWifiIterator.next().size()==0){
			sameScanWifiIterator.remove();
		}
	}

}
 
開發者ID:amgross,項目名稱:munche_prog,代碼行數:37,代碼來源:dataBaseFunctions.java

示例3: determineWinner3Players

import java.util.HashMap; //導入方法依賴的package包/類
private Player determineWinner3Players(Player winner) {
    Player playerECO = winnerEconnomicScore();
    Player playerREL = winnerReligiousScore();
    Player playerPOL = winnerPoliticalScore();
    HashMap<Player, Integer> nbVictory = new HashMap<>();
    players.forEach((p) -> {
        nbVictory.put(p, 0);
    });
    if (playerECO != null) {
        nbVictory.replace(playerECO, nbVictory.get(playerECO) + 1);
    }
    if (playerPOL != null) {
        nbVictory.replace(playerPOL, nbVictory.get(playerPOL) + 1);
    }
    if (playerREL != null) {
        nbVictory.replace(playerREL, nbVictory.get(playerREL) + 1);
    }
    Map.Entry<Player, Integer> maxVictoryPlayer = Collections.max(nbVictory.entrySet(), Map.Entry.comparingByValue());
    if (maxVictoryPlayer.getValue() >= 2) {
        winner = maxVictoryPlayer.getKey();
    } else if (playerECO != null) {
        winner = playerECO;
    } else if (playerPOL != null) {
        winner = playerPOL;
    } else if (playerREL != null) {
        winner = playerREL;
    }
    return winner;
}
 
開發者ID:sebastienscout,項目名稱:Himalaya-JavaFX,代碼行數:30,代碼來源:Board.java

示例4: interpretKeystrokes

import java.util.HashMap; //導入方法依賴的package包/類
private void interpretKeystrokes(HashMap<String, Boolean> keystrokes) {
    if (keystrokes.get("ENTER")) {
        currentState.setCmd(assetIterator.getCommand());
        dispatchCommandForConfig(assetIterator.getCommand());
        keystrokes.replace("ENTER", false);
    }

    /* Keypress combinations with CONTROL+[some key] cycle MODE or TYPE */

    /* CONTROL+{UP/DOWN}: Cycle MODE */
    else if (keystrokes.get("CONTROL") && keystrokes.get("UP")) {
        assetIterator.prev();           //CONTROL+UP: Previous Mode
    } else if (keystrokes.get("CONTROL") && keystrokes.get("DOWN")) {
        assetIterator.next();           //CONTROL+DOWN: Next Mode
    }

    /* CONTROL+{LEFT/RIGHT}: Cycle TYPE */

    else if (keystrokes.get("CONTROL") && keystrokes.get("LEFT")) {        //CONTROL+LEFT: Previous Type
        assetIterator.prevType();
    } else if (keystrokes.get("CONTROL") && keystrokes.get("RIGHT")) {     //CONTROL+RIGHT: Next Type
        assetIterator.nextType();
    }

    /* Keypresses without control cycle TYPE INSTANCES and COMMANDS */

    //LEFT/RIGHT: Cycle Type Instances
    else if (!(keystrokes.get("CONTROL")) && keystrokes.get("LEFT")) {
        assetIterator.prevInstance();
    } else if (!(keystrokes.get("CONTROL")) && keystrokes.get("RIGHT")) {
        assetIterator.nextInstance();
    }

    /* UP/DOWN: Cycle Commands */
    else if (!(keystrokes.get("CONTROL")) && keystrokes.get("UP")) {               /* Previous command */
        assetIterator.prevCommand();
    } else if (!(keystrokes.get("CONTROL")) && keystrokes.get("DOWN")) {      /* Next command */
        assetIterator.nextCommand();
    }
    else{
        return;
    }
    updateView(assetIterator);
}
 
開發者ID:Team-Fourtran,項目名稱:OOPIter2,代碼行數:45,代碼來源:MessageGenerator.java


注:本文中的java.util.HashMap.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。