[英]find string at array index? Java
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处找到字符串(i是方法中确定的随机变量)。 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". 假设我= 2,我想返回“东方”。 Is there any built-in Java method to do this, or do I have to use a loop? 有内置的Java方法可以执行此操作吗?还是必须使用循环? Thanks. 谢谢。
String myDirection = directionsList[i];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.