我創建了一個Java堆棧並添加了一些自定義對象。這些對象包含唯一的ID作爲其字段之一。我需要根據唯一名稱獲取堆棧中該對象的索引。請找到例子。在堆棧中搜索
class TestVO{
private String name;
private String uniqueId;
//getters and setters
}
public class TestStack{
public static void main(String args[]){
TestVO vo1=new TestVO();
TestVO vo2=new TestVO();
TestVO vo3=new TestVO();
vo1.setName("Test Name 1")
vo1.setId("123")
vo2.setName("Test name 2");
vo2.setId("234");
Stack<TestVO> stack=new Stack<TestVO>();
stack.add(vo1);
stack.add(vo2);
//I need to get the index of a VO from stack using it's unique ID
}
}
有人可以幫我實施嗎?
爲什麼你需要使用堆棧?一個堆棧不適合這個。這是功課嗎? – strager 2010-06-07 00:53:56
我需要構建一個麪包屑導航。我認爲堆棧很方便。 – Apps 2010-06-07 01:01:34