I have a text file structured like this:
class Object0 extends Object1
class Object2 extends Object3
class Object1
class Object4 extends Object1
class Object3
I want to split each string and store it. I know how to do this when the number of strings is known on each line, however in this case there can either be two or four words on a given line.
Here's what I have for splitting when the number of strings are known:
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.lengthto check if it's 2 or 4.workingcode?