0
字符串分割数量不明的我有结构化的这样一个文本文件:爪哇 - 每行
class Object0 extends Object1
class Object2 extends Object3
class Object1
class Object4 extends Object1
class Object3
我想要分割每个字符串,并将其存储。我知道如何在每行上已知字符串数量的情况下执行此操作,但在这种情况下,给定行上可能有两个或四个字。
这里就是我有分裂时的已知串的数量:
public static void main(String[] args) {
try {
File f = new File("test.txt");
Scanner sc = new Scanner(f);
while(sc.hasNextLine()){
String line = sc.nextLine();
String[] details = line.split(" ");
String classIdentifier = details[0];
String classNameFirst = details[1];
// String classExtends = details[2];
// String classNameSecond = details[3];
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
使用'details.length'来检查它是否是2或4 – daniu
什么是你的定义了'工作代码? – Incognito