I am trying to insert multiple objects in a TreeSet . The problem is one object inserts fine, but when I insert second object and tries to view both objects, I get the second object twice. How can I prevent my old values from getting replaced..
This is my POJO
public Class Question implements Comparable<Question>
{
.....
public int compareTo(Question q) {
if(vote>q.vote)
return -1;
else
return 1;
}
And this is the function which inserts object into the treeSet
public void save(String ques, String sessionId, Question question)
{
question.setQuesId(++quesId);
question.setQues(ques);
question.setSessionId(sessionId);
question.setVote(0);
setDemo.add(Question);
}
Note: "setDemo" is my treeSet object
Any advices are appreciated. Thankyou