`

Java基础修炼

    博客分类:
  • Java
阅读更多

 

Java编程Best Practice

Map遍历 Best Practice: 

Map<K, V> map = new HashMap<K, V>();

// for 比 while 效率高

// JDK 1.4
for (Iterator<Entry<K, V>> entryKeyIterator = map.entrySet().iterator(); entryKeyIterator.hasNext(); ) {
	Entry<K, V> item = entryKeyIterator.next();
	K key = item.getKey();
	V value = item.getValue();
}

// JDK 1.5
for (Map.Entry<K, V> item : map.entrySet()) {
	K key = item.getKey();
	V value = item.getValue();
}

  see: keySet与entrySet遍历HashMap性能差别

 

List类型数组 定义:

List<?>[] listArray= new List<?>[n];

 

Thread.sleep(5*60*1000)  高可读性:

java.util.concurrent.TimeUnit.MINUTES.sleep(5);

  性能差异see: http://blog.51cto.com/stevex/1285767

 

 

File 的 getPath, getAbsolutePath, getCanonicalPath 的不同

 


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics