本文整理汇总了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"));
}
示例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();
}
}
}
示例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;
}
示例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);
}