Search in Stack

Posted by WPS on Stack Overflow See other posts from Stack Overflow or by WPS
Published on 2010-06-07T00:53:07Z Indexed on 2010/06/07 1:02 UTC
Read the original article Hit count: 575

Filed under:
|

Hi, I've a Java Stack created and some custom objects added to it. These objects contains unique id as one of their field. I need to get the index of that object in stack based on the unique name. Please find the example.

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
}

}

Can someone please help me to implement this?

© Stack Overflow or respective owner

Related posts about java

Related posts about stack