Demo04_Properties.java 795 B

123456789101112131415161718192021222324252627282930313233343536
  1. package J20250728;
  2. import java.util.Properties;
  3. import java.util.Set;
  4. /**
  5. * @author WanJl
  6. * @version 1.0
  7. * @title Demo04_Properties
  8. * @description
  9. * @create 2025/7/28
  10. */
  11. public class Demo04_Properties {
  12. public static void main(String[] args) {
  13. //创建一个Properties集合对象
  14. Properties prop=new Properties();
  15. //存储元素---不需要使用了,有新的方法
  16. prop.put("name","张三");
  17. prop.put("age","25");
  18. prop.put("sex","男");
  19. prop.put("username","zhangsan");
  20. prop.put("password","123456");
  21. //遍历集合
  22. Set<Object> keySet = prop.keySet();
  23. for(Object key: keySet){
  24. Object value = prop.get(key);
  25. System.out.println(key+"->"+value);
  26. }
  27. }
  28. }