1

I have this string array:

String[] directionsList = {"north", "south", "east", "west"};

and I want to find the string at index i (i is a random variable determined in the method). I have this:

String myDirection = directionsList.valueOf(i);  # I have no idea if this is even
                                                 # close to correct

So say i = 2, I want to return "east". Is there any built-in Java method to do this, or do I have to use a loop? Thanks.

1

1 Answer 1

5
String myDirection = directionsList[i];
Sign up to request clarification or add additional context in comments.

1 Comment

nevermind, it's working now. what i have is i = random.nextInt(4) where random is a Random object. thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.