Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字符串变量到字符串数组的索引???JAVA_Java_String_Arraylist_Tostring - Fatal编程技术网

字符串变量到字符串数组的索引???JAVA

字符串变量到字符串数组的索引???JAVA,java,string,arraylist,tostring,Java,String,Arraylist,Tostring,我有一个字符串数组,它工作正常,字符串被存储在数组中,但是当我想从数组中获取一个字符串并将其放入变量时,我得到了一个错误。我不明白为什么 int arraySizelink = 1; String previousUrl ; ArrayList<String> historyArray = new ArrayList<String>(); previousUrl = historyArray.indexOf(arraySizelink); 提前谢谢

我有一个字符串数组,它工作正常,字符串被存储在数组中,但是当我想从数组中获取一个字符串并将其放入变量时,我得到了一个错误。我不明白为什么

    int arraySizelink = 1; 
    String previousUrl ;

ArrayList<String> historyArray = new ArrayList<String>();

previousUrl = historyArray.indexOf(arraySizelink);
提前谢谢

我在这里和谷歌上搜索过答案,但我什么也找不到。对不起,如果以前有人问过这个问题。我还是java新手,还在学习。

需要一个对象。获取指定索引处的项

previousUrl = historyArray.get(arraySizelink);

只需进行一些调整即可获得您想要的:

int arraySizelink = 1; 

// Use the interface to declare the variable
List<String> historyArray = new ArrayList<>(); 
// If you're using Java 7+, no need to repeat the type 
// inside <> when instantiating because its figured out automatically.

// get method would take an index and return an object from the list.
String previousUrl = historyArray.get(arraySizelink);

这是不可编译的。这不是logcat错误,它在字符串列表的int的IDEindexOf中显示为语法错误?先生!你是我的救星。我对java还是个新手,大家都知道这是一个学习过程。非常感谢:我会接受的:谢谢