HashMap的简单使用

main: 

package fanxing;

import java.util.HashMap;

public class MyDemo {
	public static void main(String[] args) {
		
		//定义泛型hashmap
		//key:Integer  value:Student
		HashMap<Integer,Student> map=new HashMap<>();

		map.put(2017,new Student(2017,"Jiu Bo","15137742640"));
		map.put(2016,new Student(2016,"Jiu Sen","15137742640"));
		map.put(2015,new Student(2015,"Ying Ying","15137742640"));
		map.put(2019,new Student(2019,"Chang Shan","15137742640"));
		
		Student s=map.get(2017);
		System.out.println("exit");
		
	}

}

Student:

package fanxing;

public class Student {
	
	public int sno;
	public String name;
	public String cellPhone;
	
	public Student(int sno,String name,String cellPhone)
	{
		this.sno=sno;
		this.name=name;
		this.cellPhone=cellPhone;
	}

	@Override
	public String toString() {
		return "Student [sno=" + sno + ", name=" + name + ", cellPhone=" + cellPhone + "]";
	}
}

 

上一篇:C/C++结构体语法总结


下一篇:MySQL常用SQL(含复杂SQL查询)