import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
/** *//**
*
* @descripte reverse list
* @author Gavin.lee
* @date 2009-5-24 13:41:47
* @version 1.0
*/
public class ReverseList {
private int id;
private String name;
private String pass;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public List<ReverseList> populate() {//构建list,存放ReverseList实例。
List<ReverseList> list = new ArrayList<ReverseList>();
for (int i = 0; i < 4; i++) {
ReverseList test = new ReverseList();
test.setId(i);
test.setName("lee");
test.setPass("pass");
list.add(test);
}
return list;
}
public void commRervese() {
List<ReverseList> list = this.populate();
for (int m = list.size() - 1; m >= 0; m--) {
ReverseList reverseList = list.get(m);
System.out.print(reverseList.getId());
System.out.print(reverseList.getName());
System.out.print(reverseList.getPass());
}
}
public void stackReverse() {
List<ReverseList> list = this.populate();
Stack<ReverseList> stack = new Stack<ReverseList>(); //构建堆栈,并对list进行进出栈操作。
List<ReverseList> tempList = new ArrayList<ReverseList>();
for (ReverseList t : list)
stack.push(t);
while (!stack.empty())
tempList.add(stack.pop());
for (ReverseList string : tempList) { //获取到倒序后的list。
System.out.print(string.getId());
System.out.print(string.getName());
System.out.print(string.getPass());
}
}
public static void main(String[] args) {
new ReverseList().stackReverse();
new ReverseList().commRervese();
}
}