5月4日学习内容

本文展示了在Java中使用HashMap和ArrayList进行数据存储和遍历的操作,包括HashMap的键值对遍历以及ArrayList中嵌套HashMap的使用。同时,提到了对File类的学习和Python中Selenium库用于网络爬虫的复习。
摘要由CSDN通过智能技术生成

1.进行了HashMap集合的练习

Student.java
-----------------------------------------------
public class Student {
    private int Age;

    private String Name ;

    public Student() {
    }

    public Student(String Name, int Age) {
        this.Name = Name;
        this.Age = Age;
    }

    public int getAge() {
        return Age;
    }

    public void setAge(int age) {
        this.Age = age;
    }


    public String getName() {
        return Name;
    }

    public void setName(String name) {
        this.Name = name;
    }

}
HashMapDemo.java
--------------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<Integer,Student> hm = new HashMap<Integer,Student>();

//        创建对象
        Student s1 = new Student("张文雨",18);
        Student s2 = new Student("张文晴",12);
        Student s3 = new Student("张文川",8);

//        传入对象
        hm.put(1,s1);
        hm.put(2,s2);
        hm.put(3,s3);

//        遍历
    //  方法一,键找值
        Set<Integer> keySet = hm.keySet();
        for(Integer key : keySet){
            Student value = hm.get(key);
            System.out.println("姓名:"+value.getName()+","+"年龄:"+value.getAge());
        }
        System.out.println("--------------------");
        //    方法二,键值对对象找键和值
        Set<Map.Entry<Integer,Student>> entrySet = hm.entrySet();
        for(Map.Entry<Integer,Student> me :entrySet){
            Integer key = me.getKey();
            Student value = me.getValue();
            System.out.println("姓名:"+value.getName()+","+"年龄:"+value.getAge());
        }
    }


}

2.学习了ArrayList集合与HashMap集合的嵌套

ArraList嵌套HashMap.java
--------------------------------------------
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

public class ArrayList嵌套HashMap {
    public static void main(String[] args) {
//  创建ArrayList集合
        ArrayList<HashMap<String,String>> array= new ArrayList<HashMap<String,String>>();

//  创建HashMap集合
        HashMap<String,String> hm1 = new HashMap<String,String>();
        HashMap<String,String> hm2 = new HashMap<String,String>();
        HashMap<String,String> hm3 = new HashMap<String,String>();
//        向HashMap中添加元素
        hm1.put("1","1");
        hm1.put("2","2");
        hm2.put("3","3");
        hm2.put("4","4");
        hm3.put("5","5");
        hm3.put("6","6");
//        向ArrayList中添加HashMap集合
        array.add(hm1);
        array.add(hm2);
        array.add(hm3);
//        遍历
        for(HashMap<String,String> hm : array){
            Set<String > keySet = hm.keySet();
            for (String key : keySet){
                String value = hm.get(key);
                System.out.println(value);
            }
        }
    }
}

3.了解了File类

4.完成每日目标10集

5.复习了python爬虫selenium;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值