I am trying to take an ArrayList of strings and separate it so that i can extract a title from each line.
Here is the contents of the ArrayList:
Tom Sawyer;Twain, Mark;1972;8.50;f;
Leaves of Grass;Whitman, Walt;1975;29.99;p;
Romeo and Juliet;Shakespeare, William;1980;4.99;d;
Great Gatsby;Fitzgerald, F. Scott;1979;5.99;f;
Scarlet Letter;Hawthorne, Nathaniel;1981;4.78;f;
Whisper of the River;Sams, Ferrol;1984;21.95;f;
Moby Dick;Melville, Herman;1962;13.98;f;
Last of the Mohicans;Cooper, James Fenimore;1968;8.75;f;
Odyssey;Homer;1950;9.99;f;
Christmas Carol;Dickens, Charles;1966;12.50;f;
Les Miserables;Hugo, Victor;1988;19.98;f;
Heart of Darkness;Conrad, Joseph;1970;14.45;f;
Animal Farm;Orwell, George;1978;10.00;f;
Canterbury Tales;Chaucer, Geoffrey;1965;20.00;d;
Old Man and the Sea;Hemingway, Ernest;1966;9.95;f;
I need to make a method or something that gets the first part of the line up until the “;”.
Here is the code I was using for something similar except this is reading a data file:
while (datascanner.hasNext())
File datafile = new File (data name)
Scanner datascanner = new Scanner(datafile)
String data = datascanner.nextLine()
StringToeknizer dataParser = new StringTokenizer(data, ";")
String title = dataParser.nextToken()
I need something similar to this but instead it searches the arraylist and not the file. I will then extract the other contents on each line:
String author = dataParser.nextToken()
int CopyR = dataParser.nextToken()
and so on…
Just iterate through the list and apply your logic