如何将存储在数组中的文件发送到其他类? 我试过这段代码但是没有用。
public class abc {
....
String [] indexFiles = new String[100];
public abc (){
indexFiles [0]=image1.txt;
indexFiles [1]=image1.txt;
....
draw = new drawing (indexFiles(0)); // I got error in this code
draw = new drawing (indexFiles.get(0)); // I also tried this code but it give me error as well.
}
}
答案 0 :(得分:4)
您的绘图类是采用字符串数组还是只采用单个字符串?
如果需要数组,请使用:
draw = new drawing(indexFiles);
如果需要一个字符串,请使用:
draw = new drawing(indexFiles[0]);
要访问数组中的单个值,请使用[]括号,而不是括号。
只是旁注:“get(0)”方法用于像ArrayList这样的集合:
List<String> stringList = new ArrayList<String>();
stringList.add("MyString");
System.out.println(stringList.get(0));
答案 1 :(得分:2)
使用
indexFiles[0]