I am doing an assignment for a data structures class that involves manipulating data from a csv file. I have read in the file and converted each row of the file to a string array, and then added each row to an array list of string arrays. However, whenever I print out the rows, I get the address of the array. I have already tried converting the row to a string so I know that I am reading in the file correctly. However, whenever I have tried to index the row to find a certain value, I have been indexing the address instead of the actual string array.
Any help is appreciated.
public static void readData() {
int count = 0;
Scanner file = null;
ArrayList<String[]> content = new ArrayList<String[]>();
try {
file = new Scanner(new File("compas-scores.csv"));
while (file.hasNextLine()) {
String line = file.nextLine();
// Defendant d = new Defendant(line);
String[] row = line.split(",");
// System.out.println(row);
// System.out.println(row.toString());
// String s = Arrays.toString(row);
// System.out.println(s);
content.add(row);
count++;
}
} catch (FileNotFoundException e) {
System.err.println("Cannot locate file.");
System.exit(-1);
}
// System.out.println(content);
file.close();
for (String[] row : content){
String s = Arrays.toString(row);
// System.out.println(s);
// if (nonViolent.contains()){
// System.out.println("nonViolent");
// }else{
// System.out.println("violent");
// }
}
}
When I print the row I get an address like this: Ljava.lang.String;@58a55449 When I type s = Arrays.toString(row) I get the text that is in the csv file, but when I attempt to index it I am indexing individual characters, which makes sense to me.
Here is a look at the csv file
sex,race,c_charge_degree,c_charge_desc,decile_score,score_text,two_year_recid,r_charge_desc,r_charge_degree
Male,Other,F,Aggravated Assault w/Firearm,1,Low,0,,
Male,African-American,F,Felony Battery w/Prior Convict,3,Low,1,Felony Battery (Dom Strang),(F3)
Male,African-American,F,Possession of Cocaine,4,Low,1,Driving Under The Influence,(M1)
Male,African-American,F,Possession of Cannabis,8,High,0,,
Male,Other,F,arrest case no charge,1,Low,0,,
Male,Other,M,Battery,1,Low,0,,
Male,Caucasian,F,Possession Burglary Tools,6,Medium,1,Poss of Firearm by Convic Felo,(F2)
Male,Other,F,arrest case no charge,4,Low,0,,
Female,Caucasian,M,Battery,1,Low,0,,
Male,Caucasian,F,Insurance Fraud,3,Low,1,Battery,(M1)
Male,Caucasian,F,"Poss 3,4 MDMA (Ecstasy)",4,Low,0,,
Male,African-American,M,Battery,6,Medium,1,Driving License Suspended,(M2)
Female,Caucasian,M,Battery,1,Low,0,,
Male,African-American,F,"Poss3,4 Methylenedioxymethcath",4,Low,0,,