java中properties作用,java中Properties有什么用,举例说明?

本文介绍了Java中Properties类的使用,展示了如何存储和检索键值对。通过示例代码,解释了如何添加键值对、遍历并打印所有键值对,以及如何获取不存在键的默认值。这对于Java配置文件和字符串操作非常有用。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

马克-to-win:Properties里面存着也是键值对,而且它更方便java对配置文件,字符串的操作,

例:3.9.1

import java.util.*;

public class TestMark_to_win {

public static void main(String args[]) {

Properties sala = new Properties();

Set name;

String str;

sala.put("zs", "1111");

sala.put("ls", "2222");

sala.put("ww", "3333");

sala.put("zl", "4444");

// Show all name and sala in hashtable.

name = sala.keySet(); // get set-view of keys

Iterator itr = name.iterator();

while (itr.hasNext()) {

str = (String) itr.next();

System.out.println("The sala of " +

/* public String getProperty(String key)Searches for the property

* with the specified key in this property list.*/

str + " is " + sala.getProperty(str) + ".");

}

System.out.println();

// look for state not in list -- specify default

/*

* Searches for the property with the specified key in this property

* list. The method returns the default value argument if the property

* is not found.

*/

str = sala.getProperty("Mark", "Not Found");

System.out.println("The sal of Mark is " + str + ".");

}

}

结果:

。。。。。。。。。。。。。。。。。

详情黏贴以下网址在地址栏后请进:http://www.mark-to-win.com/JavaBeginner/JavaBeginner7_web.html#DefinitionUsageOfProperties

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值