一:兩種方式效率比較
1:
for (int i = 0; i < n; i++) { String sp = bf.readLine(); if (sp.charAt(0)=='i'){ hashSet.add(sp.substring(7)); }else { System.out.println(hashSet.contains(sp.substring(5))?"yes":"no"); } }
2:
for (int i = 0; i < n; i++) { String[] sp = bf.readLine().split(" "); if (sp[0].equals("insert")){ hashSet.add(sp[1]); }else { System.out.println(hashSet.contains(sp[1])?"yes":"no"); } }
結論 1的效率比2高,當1000000級別數據進行試驗,速度大約提高0.3秒左右;
二
StringBuilder比System.out.println()效率要很多很多
結論 當1000000級別數據進行試驗,速度大約提高1秒左右;