我的方法readDataFromFile()可以讀取文本文件,例如:Bird Golden Eagle EddieMammal Tiger TommyMammal Lion LeoBird Parrot PollyReptile Cobra Colin第一列是動物的“類型”,第二列是“物種”,第三列是“名稱”。電流輸出:Bird Golden Eagle < (Golden and Eagle count as different substrings). Mammal Tiger Tommy Mammal Lion Leo Bird Parrot Polly Reptile Cobra Colin我將如何使用這種useDelimiter方法將“金鷹”算作一個物種?當前代碼:while(scanner.hasNextLine()) { String type = scanner.next(); String species = scanner.next(); String name = scanner.next(); System.out.println(type + " " + species + " " + name); scanner.nextLine(); addAnimal( new Animal(species, name, this) ); }
使用useDelimiter()聯(lián)接子字符串
慕田峪9158850
2021-05-12 18:19:00