fork download
  1. import java.util.*;
  2.  
  3. class Main {
  4. public static HashMap<String, String> lista = new HashMap<>();
  5.  
  6. private static void Put(String teste, String outra) {
  7. for (int i = 0; i < 100000; i++) if (lista.containsKey("antonio")) lista.put(teste, outra);
  8. }
  9.  
  10. private static void Replace(String teste, String outra) {
  11. for (int i = 0; i < 100000; i++) lista.replace(teste, outra);
  12. }
  13.  
  14. public static void main(String[] args) {
  15. long inicio = System.currentTimeMillis();
  16. Put("antonio", "antonio");
  17. System.out.println("Put: " + (System.currentTimeMillis() - inicio) + " ms");
  18. inicio = System.currentTimeMillis();
  19. Replace("antonio", "antonio");
  20. System.out.println("Replace: " + (System.currentTimeMillis() - inicio) + " ms");
  21. }
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/319076/101
Success #stdin #stdout 0.12s 36712KB
stdin
Standard input is empty
stdout
Put: 14 ms
Replace: 8 ms