Stack是java中实现栈的一种操作.
栈的特点:先进后出,所有的内容从栈顶取出,新增加的内容都保存在栈顶之中.
栈的操作:
入栈: public E push(E item)
出栈: public E pop()
示例:
package com.ares.stackdemo; import java.util.Stack; public class StackDemo { public static void main(String[] args) { Stack<String> s = new Stack<String>(); s.push("A"); s.push("B"); s.push("C"); System.out.println(s.pop()); System.out.println(s.pop()); System.out.println(s.pop()); System.out.println(s.pop()); // 栈已经没有内容,报错. } }输出结果是 :C,B,A
属性文件的后缀是:*.properties,java中专门操作属性的类是Properties类.
定义: public class Properties extends Hashtable<Object,Object>
此类是HashTable的子类,所有属性都是以字符串的形式出现,所以不要加入其他任何非String对象.
示例:
package com.ares.propertiesdemo; import java.util.Properties; public class PropertiesDemo01 { public static void main(String[] args) { Properties pro = new Properties(); pro.setProperty("BJ", "BeiJing"); pro.setProperty("NJ", "NanJing"); pro.setProperty("TJ", "TianJin"); System.out.println("属性存在:" + pro.getProperty("BJ")); System.out.println("属性不存在:" + pro.getProperty("SC")); System.out.println("属性不存在,指定默认值:" + pro.getProperty("SC", "没有此属性!")); } }
没有的属性会返回null,没有属性,但是设置了返回值,则返回设置的属性.
store操作:
try { pro.store(new FileOutputStream(new File("d:" + File.separator) + "area.properties"), "Area Info"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
load操作 :
pro.load(new FileInputStream(new File("d:" + File.separator + "area.properties")));
storeToXML操作 :
pro.storeToXML(new FileOutputStream(new File("d:" + File.separator) + "area.properties"), "Area Info");
loadFromXML操作 :
pro.loadFromXML(new FileInputStream(new File("d:" + File.separator + "area.properties")));
20150519
JAVA学习笔记系列
--------------------------------------------
联系方式
--------------------------------------------
Weibo: ARESXIONG
E-Mail: [email protected]
------------------------------------------------