HashTable哈希表;对象流

HashTable

HashMap&HashTable

编号比较HashMapHashTable
1线程安全
2key=null
3value=null
4效率

在这里插入图片描述
在这里插入图片描述

package com.ffyc.map;

import javax.print.DocFlavor;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class HashTableDemo01 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        Map<String,Integer> table = new Hashtable<>();//线程安全

//        map.put("a",123);
//        map.put("b",456);
//        map.put(null,1);
//        map.put(null,null);//覆盖掉1了
//        map.put("c",789);
//
//        System.out.println(map.get(null));


        table.put("a",123);
        table.put("b",456);
        table.put(null,1);
        table.put(null,null);
        table.put("c",null);

        System.out.println(table.get(null));//Exception in thread "main" java.lang.NullPointerException


    }
}

Properties 属性

在这里插入图片描述

ymal–>学习python的

属性,读取文件格式 要写成:key = value eg:xyz=123;

文件格式:xxxx.properties

在这里插入图片描述

package com.ffyc.map;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.Properties;
import java.util.Scanner;

public class PropertiesDemo02 {
    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        Reader reader = new FileReader("D:\\java-workspace\\FF20240725\\src\\com\\resources\\User.properties");
        properties.load(reader);

//        System.out.println(properties.getProperty("xyz"));
//        System.out.println(properties.getProperty("user.username"));
/*
**User.properties文件:
 * #xyz=123
 * #abc=456
 * #wyz=666
 *
 * #user.username=yabi
 * #user.password=123
 */
        Scanner sc = new Scanner(System.in);
        System.out.println("用户户名:");
        String username =  sc.nextLine();

        System.out.println("密码:");
        String password = sc.nextLine();

        if (username.equals(properties.getProperty("user.username"))
        && password.equals(properties.getProperty("user.password"))){
            System.out.print("登陆成功");
        }else {
            System.out.print("用户名|密码错误");
        }

    }
}

对象流——存储对象

在这里插入图片描述

初打印

在这里插入图片描述

改良

在这里插入图片描述

在这里插入图片描述

序列化/反序列化

序列化:给对象编号拆开,到了再反序列化组装。

在这里插入图片描述

末尾不确定 不要用循环

在这里插入图片描述

在这里插入图片描述

存多个对象时

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

Map

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值