我在按索引显示数组时遇到问题,我不知道为什么会发生这种情况。任何帮助将不胜感激。这是我的代码片段:
// create token2
String token2 = "";
// create Scanner inFile2
Scanner inFile2 = new Scanner(new File
("/Users/timothylee/KeyWestHumid.txt")).
useDelimiter(",\\s*");
// create temps2
List<String> temps2 = new LinkedList<String>();
// while loop
while(inFile2.hasNext()){
// find next
token2 = inFile2.next();
// initialize temps2
temps2.add(token2);
}
// close inFile2
inFile2.close();
// create array
String[] tempsArray2 = temps2.toArray(new String[0]);
// for-each loop
for(String ss : tempsArray2){
// display ss
System.out.println(tempsArray2[0]);
}
// for-each loop
for(String ss : tempsArray2){
// display ss
System.out.println(tempsArray2[0]);
你的问题就在这里。你实际上并没有使用ss
根本没有变量,您只需每次循环时显示第一个字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)