java中Properties有什么用,举例说明?
2017-04-14 21:39
225 查看
马克-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
例: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
相关文章推荐
- java中HashMap有什么用,举例说明?
- java中Vector有什么用,举例说明?
- java中泛型有什么用,举例说明?
- java中Stack有什么用,举例说明?
- java中LinkedList有什么用,举例说明?
- java中TreeSet有什么用,举例说明?
- java中Collections有什么用,举例说明?
- java自定义jar包读取Excel(包含2003和2007)数据,并举例说明
- 举例说明java中静态代码块、非静态代码块、构造函数的执行顺序
- java开发线程篇3:同步和异步有何异同,在什么情况下分别使用他们?举例说明。
- java中接口interface有什么用呢?举例!
- java中输出一个字符串里面的空格,字母还有数字的数目举例说明
- java中如何打印规定图案? 举例说明
- java String 缓冲池概念的举例说明
- java中抽象类和抽象方法到底什么关系?请举例说明!
- java中downcast向下转型到底有什么用? 举例说明!
- java重载时自动转换咋回事?举例说明
- 举例说明android中出现java.lang.IllegalStateException: database not open这种错误的原因及解决办法
- java中的排序除了冒泡以来, 再给出一种方法, 举例说明
- java中的单例模式,举例说明。