首先,看起来您正在使用 String 作为数组。这通常是一种反模式,应该避免。我不确定这个字符串是从哪里来的,但是问问你自己是否不能进行设置,以便像这样而不是在字符串中传递这些信息。
String []  values = new String {
   "12",
   "123",
   "4",
   "5678",
   "ans123"
}; //here the 'ans' would always be the last index, obviously tailor your array to be whats 
   // mosts convienent for you. 
我在一个巨大的肢体上猜测主题是选择和多项选择问题的答案?在这种情况下,您可能需要一组可能的答案和一个指向哪个答案的索引存储...
 String []  values = new String {
   "12",
   "123",
   "4",
   "5678"
};
int correctAnsIndex = 1;
int userAnsIndex = 2;
String correctAns = values[ansIndex];
booelan isCorrect = (userAnsIndex == correctAnsIndex);
ect, ect, ect... 
如果你不能改变这一点,一个 hacky 的解决方案就是 split 命令。 
"12_123_4_5678_ans123".split("_");将像这样返回数组 {"12","123","4","5678","ans123"};
得到答案看起来像这样......
String [] values = "12_123_4_5678_ans123".split("_"); 
String answer = null; 
for(String s : values  ) {
    if( s.startsWith("ans")){
        answer = s; 
    }
 }