可能重复:
how to check whether an element already exists in the array
我正在为黑莓开发一个应用程序,它就像一张试卷,每次用户点击开始按钮时,从包含20个问题的xml数据库中显示10个问题,然后结果以百分比显示。
现在我要做的是将每个被删除的问题存储到blackberry persitentobject中,这样当一个测试结束并且用户退出应用程序时,再次当他启动应用程序时,已经有10个问题此次显示的早期测试不应显示。
我已经将persistentobject用于其他要求,但是在这种情况下我面临着与内存相比较的问题,我发送的值是否已经存在于内存中。因此,如果有人能帮助我编写代码,那对我来说非常有帮助。
我正在给页面... Plz帮助我比较我应该是什么逻辑来比较我发送的DBMain页面到TestScreen页面的数据是否已经存在,如果它已经存在于内存中,那么就不要发送那个价值。
DBMain Page
public static int getQuestionNumber() {
//int quesCount;
//quesCount++;
//synchronized (curQues) {
//quesCount = Integer.parseInt((String)curQues.getContents());
//}
quesCount++;
synchronized (curans) {
int b=Integer.parseInt(TopManager.corrCount);
curans.setContents(b+"");
curans.commit();
}
//int quesNum[];
synchronized (qStore) {
quesNum=(int[]) qStore.getContents();
System.out.println("The value of question is ...."+quesNum.length);
}
synchronized (pQues) {
int a=Integer.parseInt(TopManager.quesNumber);
pQues.setContents(a+"");
pQues.commit();
}
if (quesNum!=null && quesCount < quesNum.length) {
synchronized (curQues) {
curQuesnew=quesNum[quesCount];
curQues.setContents(curQuesnew+"");
curQues.commit();
}
for (int i=0; i< c.length; i++) {
c[i]=TestScreen.quesNumbernew[i];
}
//i have used this logic to save the data which i am sending to the other page// synchronized (disques) {
Vector data = new Vector();
data.addElement(quesNum[quesCount]+"");
disques.setContents(data);
disques.commit();
}
synchronized (disques) {
data = (Vector)disques.getContents();
}
if (data.contains(quesNum)){ //i hav used this logic to compare the data i am sending,& the data that is already present,bt its nt working//
xyz=quesNum[quesCount];
}
return xyz;//this is the data which i am actually sending//
} else {
initialize();
quesCount = -1;
return getQuestionNumber();
}
}
TestScreen页面 //这是我们向其发送数据的页面//
String title = "";
quesNumber = DBMain.getQuestionNumber();//this is where the value is coming//
System.out.println("the value of QUESNUMBERNEW:"+quesNumbernew[i]);
//quesNumber.addElement(DBMain.getQuestionNumber()+"");
//int a=quesNumber.elementAt(quesNumber);
System.out.println("the value of QUESNUMBER:"+quesNumber);
DBMain.curQuestion = (Question) XMLParser.questionList
.elementAt(quesNumber);
title = DBMain.curQuestion.getTitle();
String BlankSpace = " ";
String choice1 = "A. " + DBMain.curQuestion.getChoice1() + "\n" + " ";
String choice2 = "B. " + DBMain.curQuestion.getChoice2() + "\n" + " ";
String choice3 = "C. " + DBMain.curQuestion.getChoice3() + "\n" + " ";
String choice4 = "D. " + DBMain.curQuestion.getChoice4() + "\n" + " ";