From 3cead7f6fd6121308dc4523635fbd05c44e17ace Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Fri, 23 Oct 2026 14:46:35 +0800 Subject: [PATCH] =?UTF-8?q?s-day09--Properties=20=E7=9A=84=E7=89=B9?= =?UTF-8?q?=E7=82=B9=E4=B8=8E=E5=9F=BA=E6=9C=AC=E4=BD=BF=E7=94=A8(?= =?UTF-8?q?=E9=87=8D=E7=82=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/inmind/properties06/Demo16.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 s-day09/src/com/inmind/properties06/Demo16.java diff --git a/s-day09/src/com/inmind/properties06/Demo16.java b/s-day09/src/com/inmind/properties06/Demo16.java new file mode 100644 index 0000000..bad73e0 --- /dev/null +++ b/s-day09/src/com/inmind/properties06/Demo16.java @@ -0,0 +1,38 @@ +package com.inmind.properties06; + +import java.util.Properties; +import java.util.Set; + +/* +19.Properties 的特点与基本使用(重点) + + 构造方法 + public Properties() :创建一个空的属性列表。 + + 常用的存储方法 + public Object setProperty(String key, String value) : 保存一对属性。 + public String getProperty(String key) :使用此属性列表中指定的键搜索属性值。 + public Set stringPropertyNames() :所有键的名称的集合。 + + 注意: + 1.Properties类似一个HashMap + 2.它真正的作用,能够将指定的配置文件的信息读取到Properties的对象 + */ +public class Demo16 { + public static void main(String[] args) { + Properties properties = new Properties(); + //存放键值对 + properties.setProperty("username","lisi"); + properties.setProperty("password","123456"); + properties.setProperty("email","111@qq.com"); + //格局属性键找值 + Object value = properties.get("username"); + System.out.println(value); + System.out.println(properties.get("password")); + + Set keys = properties.stringPropertyNames(); + for (String key : keys) { + System.out.println(key); + } + } +}