当前位置: 首页>>代码示例>>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;未经允许,请勿转载。