How do I compare a string in an array to a string?

Posted by user1641312 on Stack Overflow See other posts from Stack Overflow or by user1641312
Published on 2012-09-02T03:23:57Z Indexed on 2012/09/02 3:38 UTC
Read the original article Hit count: 101

Filed under:

EDIT: IT'S FIXED, THANKS FOR THE HELP!

So basically I have an array of strings, a question and an answer

public static String[][] triviaData = { 
    {"Question2", "Answer1"},
    {"Question2", "Answer2"},
    {"Question3", "Answer3"},
};

And I am trying to make a method that validates an entered input, lets call the entered input enteredAnswer. enteredAnswer is stored as a String.

I am trying to validate that the enteredAnswer is the same as the second index of the array.

if (enteredAnswer.equalsIgnoreCase(triviaData[Config.CurrentQuestion][1])) {

This is the code I tried, but I get the error "Cannot invoke equalsIgnoreCase(String) on the array type String[]"

I am a beginner programmer so if you could help me out it would be highly appreciated. Thanks.

enteredAnswer is stored as

public String[] enteredAnswer;

© Stack Overflow or respective owner

Related posts about java