Substring - StringIndexOutOfBounds exception java - java

I've been working on a program to collect data from a file and do some stuff to it (as evident in the code and pseudocode) however I'm having difficulty getting each element of the string into the right array. A line from a file looks like this:
1980 Aug 945 100 Allen
I'm wanting to use the substring method because that'd be the easiest in my opinion. Is there a better way of doing it? Here's my code thus far. Where does the problem lie exactly, and how should I fix it? Thanks! :)
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.lang.String;
public class Hurricanes2
{
public static void main(String [] args) throws IOException
{
int counter = 0;
String [] token = new String[1000];
String [] tokenElements = new String[128];
String [] hurricaneYear = new String[64];
String [] hurricaneName = new String[64];
String [] hurricaneMonth = new String[64];
int [] hurricaneCategory = new int[64];
double [] hurricanePressure = new double[64];
double tempKnots;
double knotsToMph;
double [] hurricaneWindSpeed = new double[64];
double categoryAverage;
double pressureAverage;
double speedAverage;
String headerData = " Hurricanes 1980 - 2006\n\n Year Hurricane Category Pressure(MB) Wind Speed (MPH)\n========================================================================";
Scanner in = new Scanner(System.in);
Scanner inFile = new Scanner(new File("hurcData2.txt"));
System.out.println(headerData);
/**---Use for-each (line:token)
* Parse for year - > year array
* parse for name - > name array
* parse for knots - > tempKnots
* knotsToMph = tempKnots * 1.15078
* hurricaneWindSpeed[counter] = knotsToMph
* enter if-else to calculate category (hurricaneCategory [] = 1,2,3,4, or 5):
* 74-95 cat1
* 96-110 cat2
* 111 - 129 cat3
* 130-156 cat4
* 157 or higher cat 5
*
*
*/
while(inFile.hasNextLine()){
token[counter] = inFile.nextLine();
String tempToken = token[counter];
hurricaneYear[counter] = tempToken.substring(0, 3);
hurricaneMonth[counter] = tempToken.substring(6, 8);
hurricanePressure[counter] = Double.parseDouble(tempToken.substring(10, 12));
hurricaneWindSpeed[counter] = Double.parseDouble(tempToken.substring(14, 16));
hurricaneName[counter] = tempToken.substring(17);
counter++;
}
System.out.print("Lines: " + counter);
}
}

You can split the string into arrays with regex:
String s = "1980 Aug 945 100 Allen";
Pattern p = Pattern.compile("\\s+");
System.out.println(Arrays.toString(p.split(s)));
or using the String.split method:
System.out.println(Arrays.toString(s.split("\\s+")));
output:
[1980, Aug, 945, 100, Allen]
[1980, Aug, 945, 100, Allen]

The title of the question lists index out of bounds exception, but it does not say if it is StringIndexOutOfBoundsException or ArrayIndexOutOfBoundsException.
You read the lines into an array that is defined to hold 1000 elements, but then put the parsed pieces of the string into arrays that are only defined to hold 64 elements.
It could be that your parsing logic is OK but the array's are getting over filled.

You could probably do something like this:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class test {
public void converter(String[] stringArray) {
int counter = 0;
String [] token = new String[1000];
String [] tokenElements = new String[128];
String [] hurricaneYear = new String[64];
String [] hurricaneName = new String[64];
String [] hurricaneMonth = new String[64];
int [] hurricaneCategory = new int[64];
double [] hurricanePressure = new double[64];
double tempKnots;
double knotsToMph;
double [] hurricaneWindSpeed = new double[64];
double categoryAverage;
double pressureAverage;
double speedAverage;
String headerData = " Hurricanes 1980 - 2006\n\n Year Hurricane Category Pressure(MB) Wind Speed (MPH)\n========================================================================";
Scanner in = new Scanner(System.in);
Scanner inFile = null;
try {
inFile = new Scanner(new File("hurcData2.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(inFile.hasNextLine()){
String line = inFile.nextLine();
String[] arrayOfString = line.split(" ");
}
System.out.print("Lines: " + counter);
}
}
The issue with incompatible types is because you have to convert the Scanner object to a String. I did that in the while loop, so now while the scanner has a next line its going to turn that line into a string and split it on the spaces. You will have an array for all the values. Now you can perform your logic based on the position in the array.

Related

csv file and manipulation

S.M.Tido,112,145,124
P.julio,178,145,133
Carey,92,100,123
Elain,87,92,92
Theodore,178,155,167
I have read above text file, and tried to find the average values of the 3 readings in every row. But I can only find the average of a single column,because my for loop logic did not work. Can anyone show me how to find the average of every row ?
import java.util.Scanner;
import java.io.*;
public class PatientDetails{
public static void main(String[] args){
String fileName = "patient.txt";
File file = new File(fileName);
try{
Scanner inputStream = new Scanner(file);
int sum = 0;
int noOfReadings = 3;
while(inputStream.hasNext()){
String data = inputStream.next();
String[] values = data.split(",");
int readings1 = Integer.parseInt(values[1]);
int readings2 = Integer.parseInt(values[2]);
int readings3 = Integer.parseInt(values[3]);
sum = readings1 + readings2 + readings3;
}
inputStream.close();
System.out.println("Average = "+sum/noOfReadings);
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}
}
Note:
Note : I have not learnt data structures in Java so I cannot use lists
In my code.
Just move you println() into the loop, and after that, change the sum back to 0.
Scanner inputStream = new Scanner(file);
int sum = 0;
int noOfReadings = 3;
while (inputStream.hasNext()) {
String data = inputStream.next();
String[] values = data.split(",");
int readings1 = Integer.parseInt(values[1]);
int readings2 = Integer.parseInt(values[2]);
int readings3 = Integer.parseInt(values[3]);
sum = readings1 + readings2 + readings3;
System.out.println("Average = " + sum / noOfReadings);
sum = 0;
}
inputStream.close();

How to count unique words in a text file?

I have implemented code to count number of:
- chars
- words
- lines
- bytes
in text file.
But how to count dictionary size: number of different words used in this file?
Also, how to implement iterator which can iterate over only letters? (Ignore whitespaces)
public class wc {
public static void main(String[] args) throws IOException {
//counters
int charsCount = 0;
int wordsCount = 0;
int linesCount = 0;
Scanner in = null;
File file = new File("Sample.txt");
try(Scanner scanner = new Scanner(new BufferedReader(new FileReader(file)))){
while (scanner.hasNextLine()) {
String tmpStr = scanner.nextLine();
if (!tmpStr.equalsIgnoreCase("")) {
String replaceAll = tmpStr.replaceAll("\\s+", "");
charsCount += replaceAll.length();
wordsCount += tmpStr.split("\\s+").length;
}
++linesCount;
}
System.out.println("# of chars: " + charsCount);
System.out.println("# of words: " + wordsCount);
System.out.println("# of lines: " + linesCount);
System.out.println("# of bytes: " + file.length());
}
}
}
To get unique words and their counts:
1. Split your obtained line from file into a string array
2. Store the contents of this string array in a Hashset
3. Repeat steps 1 and 2 till end of file
4. Get unique words and their count from the Hashset
I prefer posting logic and pseudo code as it will help OP to learn something by solving posted problem.
Example of how my code works:
File with words "aa bb cc cc aa aa" has 3 unique words.
First, turn words into a string with each word separated by "-".
String: "aa-bb-cc-cc-aa-aa-"
Get the first word: "aa", set the UniqueWordCount = 1, and then replace "aa-" with "".
New String: "bb-cc-cc-"
Get the first word: "bb", set the UniqueWordCount = 2, and then replace "bb-" with "".
New String: "cc-cc-"
Get the first word: "cc", set the UniqueWordCount = 3, and then replace "cc-" with "".
New String: "", you stop when the string is empty.
private static int getUniqueWordCountInFile(File file) throws FileNotFoundException {
String fileWordsAsString = getFileWords(file);
int uniqueWordCount = 0;
int i = 0;
while (!(fileWordsAsString.isEmpty()) && !(fileWordsAsString.isBlank())) {
if (Character.toString(fileWordsAsString.charAt(i)).equals(" ")) {
fileWordsAsString = fileWordsAsString.replaceAll(fileWordsAsString.substring(0, i+1),"");
i = 0;
uniqueWordCount++;
} else {
i++;
}
}
return uniqueWordCount;
}
private static String getFileWords(File file) throws FileNotFoundException {
String toReturn = "";
try (Scanner fileReader = new Scanner(file)) {
while (fileReader.hasNext()) {
if (fileReader.hasNextInt()) {
fileReader.nextInt();
} else {
toReturn += fileReader.next() + " ";
}
}
}
return toReturn;
}
If you want to use my code just pass getUniqueWordCountInFile() the file that has the words for which you want to count the unique words.
hey #JeyKey you can use HashMap. Here I using Iterator too. You can check out this code.
public class CountUniqueWords {
public static void main(String args[]) throws FileNotFoundException {
File f = new File("File Name");
ArrayList arr=new ArrayList();
HashMap<String, Integer> listOfWords = new HashMap<String, Integer>();
Scanner in = new Scanner(f);
int i=0;
while(in.hasNext())
{
String s=in.next();
//System.out.println(s);
arr.add(s);
}
Iterator itr=arr.iterator();
while(itr.hasNext())
{i++;
listOfWords.put((String) itr.next(), i);
//System.out.println(listOfWords); //for Printing the words
}
Set<Object> uniqueValues = new HashSet<Object>(listOfWords.values());
System.out.println("The number of unique words: "+uniqueValues.size());
}
}

Floating Decimal, Parsing info from fileread- what is going on

okay guys im really really confused and all or any help is appropriated to the MAX!
EDIT: I am working on an assignment that deals with reading data from a text file, and parsing that data to various arrays. i am stuck on parsing, keep receiving a floating decimal error.
This is my first time ever using fileread. im trying to extract the hours and wage from employees and calculate their gross and net pay. Then i wanted to display, in alphabetical order, a managers report of all their information plus my calculated information...
i have efficiently wrote a program that displays their information. i cannot, for the life of me, find a way to parse this information to start applying my calculations. first let me show you what i have, then i will show you what i am doing and the results.
here is what i have:
import java.awt.HeadlessException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class T2 {
public static void main(String[] args)
{
String list = "";//creates a list for output GUI
System.out.println("Reading File ......");
//Name of the file with precise directory
//String fileName="data.txt"
String fileName="G:\\cs215\\assign 2\\FileRead\\READTHIS.txt"; //turns a file into string
//tring fileName="C:\\cs130\\Max_names.txt"; //turns a file into string on my PC
//Arrays to store variables for each person
String [] extra = new String [11];
String [] Name = new String [11];
String [] familyName = new String [11];
String [] FName = new String [11];
String [] credit = new String [11];
String [] hr = new String [11];
String [] wg = new String [11];
Double [] wage = new Double [11];
Double [] hrworked = new Double [11];
try{//Try tests the code inside of it for errors.
//Create object of FileReader
FileReader inputFile = new FileReader(fileName);
//Instantiate the BufferedReader Class
BufferedReader bufferReader = new BufferedReader(inputFile);
//Variable to hold the one line data
String line = null;
// Read file line by line and print on the console
int row = 0;
while ((line = bufferReader.readLine()) != null) {
extra[row]= line;
row++;
}
//Close the buffer reader
bufferReader.close();
//This loop contains and seperates each line into individual words
for (int y = 0;y<=9;y++)
{
//seperates the first word in each line from the other ones.
int u = 0;
while(u < extra[y].length())
{
if(extra[y].charAt(u) == ',')//Determines the point at which the words are seperated
{
//Splits one word and the remaining words into two variables
Name[y] = extra[y].substring(0, u);
familyName[y] = extra[y].substring(u + 1, extra[y].length());
u = extra[y].length();
}
++u;
}
//seperates the second word in each line from the other ones.
int a = 0;
while(a < familyName[y].length())
{
if(familyName[y].charAt(a) == ',')//Determines the point at which the words are seperated
{
//Splits one word and the remaining words into two variables
FName[y] = familyName[y].substring(0, a);
credit[y] = familyName[y].substring(a + 1, familyName[y].length());
a = familyName[y].length();
}
++a;
}
//Puts the words back together in re-sorted order
extra[y] = ("" +FName[y] +", "+Name[y]+", " +credit[y]+ "");
}//end of sorting and resorting loop
//places each name in string.
String[] arr = {extra[0], extra[1], extra[2], extra[3],extra[4], extra[5], extra[6], extra[7], extra[8], extra[9]};
//rearanges the string in alphabetical order from top to bottom based on last name
String tmp;
for (int i = 0;i < arr.length;i++)
{
tmp = arr[i];
for (int j = 0;j < arr.length;j++)
{
if (i == j) continue;
int x = tmp.compareTo(arr[j]);
if (x < 0)
{
tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
}
//acquires the current date
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Calendar cal = Calendar.getInstance();
for (int r=0;r<10;r++)
{
int pl = 0;
while(pl < arr[r].length())
{
if(arr[r].charAt(pl) == ',')//Determines the point at which the words are seperated
{
//Splits one word and the remaining words into two variables
familyName[r] = arr[r].substring(0, pl);
Name[r] = arr[r].substring(pl + 1, arr[r].length());
pl = arr[r].length();
}
++pl;
}
//seperates the second word in each line from the other ones.
int pr = 0;
while(pr < Name[r].length())
{
if(Name[r].charAt(pr) == ',')//Determines the point at which the words are seperated
{
//Splits one word and the remaining words into two variables
FName[r] = Name[r].substring(0, pr);
credit[r] = Name[r].substring(pr + 1, Name[r].length());
pr = Name[r].length();
}
++pr;
}
//Seperates the last two words in each line
int pz = 0;
while(pz < credit[r].length())
{
if(credit[r].charAt(pz) == ',')//Determines the point at which the words are seperated
{
//Splits one word and the remaining words into two variables
hr[r] = credit[r].substring(0, pz);
wg[r] = credit[r].substring(pz + 1, credit[r].length());
pz = credit[r].length();
}
++pz;
}}
//HERE IS WHERE I AM TRYING TO PARSE THE HOURS AND WAGE FROM MY DOC
//Prompts the JPanel
JLabel tran = new JLabel("Date: " + dateFormat.format(cal.getTime()) + "");
JFrame app = new JFrame("Manager Report");
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Places all the variables in their correct spots
tran.setBounds(0, 10, 200, 20); // x, y, width, height x across, y down
JLabel tlast = new JLabel("Last Name:");
tlast.setBounds(0, 30, 200, 20);
JLabel tfirst = new JLabel("First Name:");
tfirst.setBounds(200, 30, 200, 20);
JLabel thour = new JLabel("Work hours:");
thour.setBounds(400, 30, 200, 20);
JLabel twage = new JLabel("Wage:");
twage.setBounds(600, 30, 200, 20);
JLabel Fix = new JLabel("");//This was added to make JPanel stop glitching
Fix.setBounds(1400, 30, 200, 20);
/*Goes throughthe list of people and places all the variables in their
correct spots. Note that each line output is lower than before.
*/
for (int t=0; t<=9;t++)
{
JLabel displaylname = new JLabel(""+familyName[t] +"");
displaylname.setBounds(0, 50+(20*t), 200, 20);
JLabel displayfname = new JLabel(""+FName[t]+"");
displayfname.setBounds(200, 50+(20*t), 200, 20);
JLabel displayhours = new JLabel(""+hr[t]+"hrs");
displayhours.setBounds(400, 50+(20*t), 200, 20);
JLabel displaywage = new JLabel(""+wg[t]+"$ per hr");
displaywage.setBounds(600, 50+(20*t), 200, 20);
//The required windows that allow output in the loop
app.add(displaylname);
app.add(displayfname);
app.add(displayhours);
app.add(displaywage);
}
//The required windows that allow output
app.add(tran);
app.add(tlast);
app.add(tfirst);
app.add(thour);
app.add(twage);
app.add(Fix);
app.setSize(800, 300);
app.setVisible(true);
//window.setLayout(null);
app.setResizable(false);
}//End of try
//catches the program, terminates it, and sends an error message if an error is encountered
catch(IOException | HeadlessException e){
System.out.println("Error while reading file line by line:" + e.getMessage());
}
}
}
the text doc im extracting from looks like this, firstname,last,hours,wage:
Sukken,Dey,45.0,75
Will,Duke,40,80
Adam,Kauffman,43,72
Shaun,Milson,40,65
Daniel,Jamestone,35,60
Matthew,Olberg,40,72
Andrew,Johnson,45,75
Arron,Winsen,42,70
Eric,Winsen,40,65
Mark,Dinger,45,75
im trying to parse the information into the double arrays i have defined at the top. I'm implementing these lines of code right before my promps for jpanel. i commented where.
for(int m=0; m<11; m++)
{
hrworked[m]=Double.parseDouble(hr[m]);
wage[m]=Double.parseDouble(wg[m]);
System.out.println(wage[m]);
}
i even placed a print line statement to see if the parses are working and it seems like they are until they hit an error. the output results in
run:
Reading File ......
75.0
Exception in thread "main" java.lang.NullPointerException
75.0
80.0
60.0
75.0
72.0
65.0
72.0
70.0
65.0
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at t2.T2.main(T2.java:147)
C:\Users\Adamska\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
it appears to be parsing because it prints out values for each line but it results in an error and im not sure what the cause is. is this an appropriate approach or should i be using something else to parse my values? if someone could explain what is going on and point me in what i need to do id greatly appreciate it

File resetting after running [duplicate]

This question already has answers here:
How to append text to an existing file in Java?
(31 answers)
Closed 9 years ago.
Okay, I'm coding something that will generate a crypt, and assign each letter a string of a random value of anywhere from 2 to 6
import java.io.*;
import java.util.*;
public class filewriters {
public static void main(String[] args) throws IOException{
FileWriter a = new FileWriter("crypt.txt");
char whynot[];
whynot = new char[97];
String b[] = new String[97];
for(int w = 30; w<127; w++){
char lol =(char) w;
whynot[w - 30] = lol;
a.write(lol + " : " );
String and = "";
int um = (int) (Math.random() * 5 + 1);
for(int q = 0; q<um; q++){
int well = (int)( Math.random() * 97 + 30);
char hello = (char) well;
and+= hello;
}
b[w - 30] = and;
a.write(and + "\n");
}
toencode(whynot, b);
a.close();
}
private static void toencode(char[] whynot, String[] b) throws IOException{
Scanner sc = new Scanner(System.in);
FileWriter themessage = new FileWriter("themessage.txt");
FileWriter theEncrypted = new FileWriter("encrypted.txt");
FileWriter toDecode = new FileWriter("DecodeThis.txt");
String thevar = sc.nextLine();
char lol[] = thevar.toCharArray();
for(int w = 0; w < lol.length; w++){
char a = lol[w];
themessage.write(a + " : ");
for(int q = 0; q<whynot.length; q++){
if(a == whynot[q]){
themessage.write(b[q] + "\n");
theEncrypted.write(b[q] + "\n");
toDecode.write(b[q]);
System.out.println(b[q]);
}
}
}
theEncrypted.close();
themessage.close();
toDecode.close();
}
}
Okay, it works fine, mostly. The one and only problem is that I want it to keep the contents of the previous file, and write more stuff to the file, but after every run, the previous contents of the file get removed. Can anyone help?
FileWriter has an alternate constructor which will append contents to the file, rather than writing from the beginning:
public FileWriter(String fileName,
boolean append)
throws IOException
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
Parameters:
fileName - String The system-dependent filename.
append - boolean if true, then data will be written to the end of the file rather than the beginning.

Adding text read from a file to an array list in java

I am having trouble putting text read from a file into an array list.
My text looks like this:
438;MIA;JFK;10:55;1092;447
638;JFK;MIA;19:45;1092;447
689;ATL;DFW;12:50;732;448 etc...
My code looks like this:
package filesexample;
import java.io.*;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.ArrayList;
/**
*
* #author
*/
public class FilesExample {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws IOException {
File file = new File ("/Schedule.txt");
try
{
Scanner scanner= new Scanner(file);;
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
Scanner lineScanner= new Scanner(line);
lineScanner.useDelimiter(";");
while(lineScanner.hasNext()){
String part = lineScanner.next();
System.out.print(part + " ");
}
System.out.println();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}
}
}
Some help on getting started would be much appreciated thank you!
You don't need to do the following
Scanner lineScanner= new Scanner(line);
lineScanner.useDelimiter(";");
Just do
String[] parts = line.split(";");
They all need to have there own array for each category, so flight
number will need its own array, origin its own array
I would say, don't. You don't need to have separate array for each of them.
I would rather create a class with attributes: -flight number, origin, destination, time, miles and price.
Now for every line, I would just split it on ;, and have a constructor in the class that takes an array as parameter. And rather than having separate ArrayList for each of those parameters, I would have an ArrayList of that class instance.
class Flight {
private int flightNumber;
private String origin;
private String destination;
... so on for `time, miles and price`
public Flight(String[] attr) {
this.flightNumber = Integer.parseInt(attr[0]);
this.origin = attr[1];
this.destination = attr[2];
... so on.
}
}
And then where you are using: -
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter(";");
I would use String#split() to get individual attributes, and then create an ArrayList<Flight>, and add Flight instance to it: -
List<Flight> flights = new ArrayList<Flight>();
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] attributes = line.split(";");
flights.add(new Flight(attributes));
}
NOTE : -
You can improve upon how you instantiate your Flight class, and how you set different attributes. Since your attributes are of different types, and they are in String form, so you would need to use appropriate conversion from String to Integer or String to double which I have not considered here.
use String.split(delimiter) to split your String.
List<String> list = new ArrayList<String>();
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
String[] strArr = line.split(";");
for(String s: strArr){
list.add(s); //adding a string into the list
System.out.println(s + " ");
}
}
System.out.println();
EDIT: From your comments
of the text I posted, the first number is flight number, origin, destination, time, miles and price. They all need to have
there own array for each category, so flight number will need its own
array, origin its own array etc.
you don't need an array for each property. create a class and name it Filght. and make your properties as instance variables.
class Flight {
private long filghtNo;
private String origin;
private dest;
private Date time;
private long miles;
private double price;
//setters and getters
}
List<Flight> list = new ArrayList<Flight>();
Flight flight = new Flight();
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
Scanner scan = new Scanner(line);
if(scan.hasNextLong()){
flight.setFilgthNo(scan.nextlong());
}
else if // do the same for other properties
}
list.add(flight);
This way is more Object Oriented.
I re-iterate the need for a more OO approach but here is what you need for what you asked for.
public final class FlightInfoParser {
private static final String[] EMPTY_STRING_ARRAY = new String[]{};
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
List<String> flightNumbersList = new ArrayList<String>();
List<String> originsList = new ArrayList<String>();
List<String> destinationsList = new ArrayList<String>();
List<String> departureTimesList = new ArrayList<String>();
List<Integer> milesList = new ArrayList<Integer>();
List<Double> pricesList = new ArrayList<Double>();
String line;
while ((line = r.readLine()) != null) {
String[] fields = line.split(";");
flightNumbersList.add(fields[0]);
originsList.add(fields[1]);
destinationsList.add(fields[2]);
departureTimesList.add(fields[3]);
milesList.add(Integer.parseInt(fields[4]));
pricesList.add(Double.parseDouble(fields[5]));
}
String[] flightNumbersArray = flightNumbersList.toArray(EMPTY_STRING_ARRAY);
String[] originsArray = originsList.toArray(EMPTY_STRING_ARRAY);
String[] destinationsArray = destinationsList.toArray(EMPTY_STRING_ARRAY);
String[] departureTimesArray = departureTimesList.toArray(EMPTY_STRING_ARRAY);
int[] milesArray = new int[milesList.size()];
for (int i = 0, len = milesArray.length; i < len; ++i) {
milesArray[i] = milesList.get(i);
}
double[] pricesArray = new double[pricesList.size()];
for (int i = 0, len = pricesArray.length; i < len; ++i) {
pricesArray[i] = pricesList.get(i);
}
}
}

Categories