public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三", 12) );
hashMap.put("BB", new Person("李四", 13));
hashMap.remove("BB");
System.out.println(hashMap);
}
3.void putAll(Map t);添加一个map
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三", 12) );
hashMap.put("BB", new Person("李四", 13));
HashMap hashMap2 = new HashMap();
hashMap2.put("CC", new Person("孙悟空", 500));
hashMap2.put("DD", new Person("嫦娥", 700));
hashMap.putAll(hashMap2);
System.out.println(hashMap);
}
4.void clear();清除数据
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三", 12) );
hashMap.put("BB", new Person("李四", 13));
hashMap.clear();
System.out.println(hashMap);
}
5.Object get(Object key);根据key取出value
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三", 12) );
hashMap.put("BB", new Person("李四", 13));
Person person = (Person) hashMap.get("AA");
System.out.println(person.name);
}
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三", 12) );
hashMap.put("BB", new Person("李四", 13));
hashMap.put("CC", new Person("李四", 14));
boolean containsValue = hashMap.containsValue(new Person("李四", 14));
System.out.println(containsValue);
}
说明:
自定义类做key就必须重写equals方法,这里如果不重写就返回false,否则就返回true。
8.int size();输出HashMap中键值对的个数。
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三", 12) );
hashMap.put("BB", new Person("李四", 13));
hashMap.put("BB", new Person("李四", 13));
hashMap.put(null, null);
int size = hashMap.size();
System.out.println(size);
}
说明:
这里是3,其中hashMap.put("BB", new Person("李四", 13));重复添加。
9.boolean isEmpty();判断HashMap是否为空
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", "张三");
hashMap.put(null, null);
hashMap.isEmpty();
System.out.println(hashMap);
}
10.boolean equals(Object obj);比较两个Map是否相同
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三",12));
hashMap.put("BB", new Person("李四",13));
HashMap hashMap2 = new HashMap();
hashMap2.put("AA", new Person("张三",12));
boolean equals = hashMap.equals(hashMap2);
System.out.println(equals);
}
11.Set keySet();遍历HashMap中的所有Key
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三",12));
hashMap.put("BB", new Person("李四",13));
hashMap.put("CC", new Person("王五",14));
hashMap.put("DD", new Person("陈六",14));
Set entrySet = hashMap.keySet();
for (Object entry : entrySet) {
System.out.println(entry);
}
}
12.Collection values();遍历HashMap中的value
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三",12));
hashMap.put("BB", new Person("李四",13));
hashMap.put("CC", new Person("王五",14));
hashMap.put("DD", new Person("陈六",14));
Collection values = hashMap.values();
//values的遍历方式一
for (Object object : values) {
System.out.println(object);
}
//values的遍历方式二
Iterator iterator = values.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
13.Set entrySet();遍历HashMap的键值对
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("AA", new Person("张三",12));
hashMap.put("BB", new Person("李四",13));
hashMap.put("CC", new Person("王五",14));
hashMap.put("DD", new Person("陈六",14));
Set> entrySet = hashMap.entrySet();
for (Entry entry : entrySet) {
System.out.println(entry);
}
}
1. 创建一个maven项目
2. 创建com.CoberturaStart.java
package com;
public class CoberturaStart {
public void helloEveryone(){
System.out.println("=================================================
我并不知道出现这个问题的实际原理,只是通过其他朋友的博客,文章得知的一个解决方案,目前先记录一个解决方法,未来要是真了解以后,还会继续补全.
在mysql5中有一个safe update mode,这个模式让sql操作更加安全,据说要求有where条件,防止全表更新操作.如果必须要进行全表操作,我们可以执行
SET
public class DeleteSpecificChars {
/**
* Q 63 在字符串中删除特定的字符
* 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。
* 例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”
*/
public static voi
File descriptors are represented by the C int type. Not using a special type is often considered odd, but is, historically, the Unix way. Each Linux process has a maximum number of files th