如何通过HashMap集合存储学生信息及其对应的描述字符串?

2026-04-16 14:572阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计177个文字,预计阅读时间需要1分钟。

如何通过HashMap集合存储学生信息及其对应的描述字符串?

javapackage day18;import day18.Student;import java.util.HashMap;

/** * 描述: * HashMap集合的键是Student,值是String的示例 * @author 71948 * @create 2017-10-06 22:19 */public class Demo5_JHashMap { public static void main(String[] args) { HashMap map=new HashMap(); // 假设有一个学生对象和一个与之对应的字符串 Student student1=new Student(张三, 20); String info=学生信息;

// 将学生对象和字符串添加到HashMap中 map.put(student1, info);

// 输出HashMap中的内容 System.out.println(map); }}

如何通过HashMap集合存储学生信息及其对应的描述字符串?

gistfile1.txt

package day18.HashMap; import day18.Student; import java.util.HashMap; /** * 描述: * HashMap集合键是Student值是String的案例 * * @outhor 71948 * @create 2017-10-06 22:19 */ public class Demo5_JHashMap { public static void main(String[] args) { HashMap stu = new HashMap<>(); stu.put(new Student("张三",21),"陆丰"); stu.put(new Student("李四",21),"海丰"); stu.put(new Student("王五",21),"潮州"); System.out.println(stu); } }

本文共计177个文字,预计阅读时间需要1分钟。

如何通过HashMap集合存储学生信息及其对应的描述字符串?

javapackage day18;import day18.Student;import java.util.HashMap;

/** * 描述: * HashMap集合的键是Student,值是String的示例 * @author 71948 * @create 2017-10-06 22:19 */public class Demo5_JHashMap { public static void main(String[] args) { HashMap map=new HashMap(); // 假设有一个学生对象和一个与之对应的字符串 Student student1=new Student(张三, 20); String info=学生信息;

// 将学生对象和字符串添加到HashMap中 map.put(student1, info);

// 输出HashMap中的内容 System.out.println(map); }}

如何通过HashMap集合存储学生信息及其对应的描述字符串?

gistfile1.txt

package day18.HashMap; import day18.Student; import java.util.HashMap; /** * 描述: * HashMap集合键是Student值是String的案例 * * @outhor 71948 * @create 2017-10-06 22:19 */ public class Demo5_JHashMap { public static void main(String[] args) { HashMap stu = new HashMap<>(); stu.put(new Student("张三",21),"陆丰"); stu.put(new Student("李四",21),"海丰"); stu.put(new Student("王五",21),"潮州"); System.out.println(stu); } }