I need some help with an arraylist. My assigment is to populate an arraylist with lines of text from an input.txt file. Each line has 11 data fields separated by a "-".
Here is the code:
import java.util.*;
import java.io.*;
//import javax.swing.*;
public class readin2{
public static void main(String args[]) throws IOException{
ArrayList<String> empList = new ArrayList<String>();
File file = new File("EmpDB.txt");
Scanner scan = new Scanner(file);
int i=0;
//populate List
while(scan.hasNext()){
empList.add(scan.nextLine());
//post increment i
i++;
//use i value as line numbers and output each line
System.out.println(i+") "+empList.get(i-1));
}
}
}
this is the output:
1) Currier-Glen-A-123456789-NTAD-F-2-0-1500-12-0 2) Public-John-Q-098765432-SALE-P-5-25-1000-0-120 3) Doe-Jane-S-938475610-HRMG-F-3-0-2000-9-0 4) Doe-John-H-069783049-CCEO-F-4-0-2500-12-0 5) Page-Jimmy-F-994857685-SALE-P-5-30-1000-0-360
...exactly the way it looks in the text file.
So the question remains: how do I "remove" the "-" and leave it as a space?(this is to feed another method in a subclass for manipulation in display.
Thanks

New Topic/Question
Reply



MultiQuote




|