private Scanner c;
public void openFile3() {
ArrayList<String> list3 = new ArrayList<String>(7);
try {
c = new Scanner(new File("IRStudents.txt"));
} catch (Exception e) {
System.out.println("could not find file");
}
while (c.hasNextLine()) {
list3.add(c.nextLine());
}
String[] arrayThree = list3.toArray(new String[list3.size()]);
Arrays.sort(arrayThree);
System.out.println(Arrays.toString(arrayThree));
int size = arrayThree.length;
String [] names;
for(int j = 0; j<size;j++) {
String word = arrayThree[j];
String newWord = word.substring(6, 15);
我只是试图将String
的字符从6-15放入名为names的String
数组中。我已将它们放入一个名为arrayThree
的数组中,现在我想将String
的缩短版本放入另一个名为names的数组中。
答案 0 :(得分:0)
String[] names = new String[size];
for (int j = 0; j < size; j++) {
names[j] = arrayThree[j].substring(6, Math.min(15, arrayThree[j].length()));
}