一道经常遇到的面试编程题,字符串逆序输出
public class MyTest {
public static void main(String[] args) {
String a = "qwfdvfb";
System.out.print("字符串原本的顺序:");
System.out.println(a.toCharArray());
System.out.print("字符串逆序输出:");
for (int i = 6; i >=0; i--) {
System.out.print(a.charAt(i));
}
}
}
21. HashMap 和 Hashtable 有什么区别?
- hashMap去掉了HashTable 的contains方法,但是加上了containsValue()和containsKey()方法。
- hashTable同步的,而HashMap是非同步的,效率上逼hashTable要高。
- hashMap允许空键值,而hashTable不允许。
22. 如何决定使用 HashMap 还是 TreeMap?
对于在Map中插入、删除和定位元素这类操作,HashMap是最好的选择。然而,假如你需要对一个有序的key集合进行遍历,TreeMap是更好的选择。基于你的collection的大小,也许向HashMap中添加元素会更快,将map换为TreeMap进行有序key的遍历。
23. 说一下 HashMap 的实现原