public static void main(String[] args) { List<String> list = new ArrayList<String>(); for (int i = 0; i < 1000000; i++) { list.add(String.valueOf(i)); }
long startList = System.nanoTime(); for (String string : list) { if (string.equals("100000")) { System.out.print("ArrayList-->"); long endList= System.nanoTime(); System.out.println("程序运行时间: "+(endList-startList)+"ms"); } }
Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < 1000000; i++) { map.put(String.valueOf(i), String.valueOf(i)); }
long startMap = System.currentTimeMillis(); if (map.containsKey("100000")) { System.out.print("Map-->"); long endMap= System.nanoTime(); System.out.println("程序运行时间: "+(endMap-startMap)+"ms"); } }