0

I have a .csv file with 177 rows and 18,000 odd cols.Given the column label, I should pick that particular column and as a default the first two label columns.

Please help me with this,

Thanks all,

Priya

2
  • 1
    -1 - you've apparently tried nothing, nor even looked for any possible options Commented Jul 1, 2011 at 3:45
  • I have tried storing the column labels in an array list and the values in another array list and tried calling the column via their column label. Commented Jul 4, 2011 at 9:43

3 Answers 3

1

So, what's the question? Parse CSV file. You can either implement this yourself or use third party code. If you implement it yourself read line by line, split lines line.split(",") into elements and put it into data structure that should be a map of lists:

Map<String, List<String>> table = new LinkedHashMap<String, List<String>>();

Use column name as a key and column values as a list elements. LinkedHashMap is preferable here to preserve the order of your columns.

Read first line that contains the column names and create list instances:

table.put(columnName, new LinkedList<String>());

Additionally create an array of column names:

String[] columns = new String[0];
table.keys().toArray();

Now continue iterating over your data and populate your table:

String[] data = line.split(",");
for (int i = 0;  i < data.length;  i++) {
    table.get(columns[i]).add(data[i]);
}

TBD... Good luck.

Sign up to request clarification or add additional context in comments.

1 Comment

hi, so if i use the linked hash map i can store the column names as keys and the values as the list?i m bit confused on how to store the whole column as a list? Anyhow thank u very much for giving ur time..
0

Have you looked into OpenCSV ?

1 Comment

N, i haven't, I usually read it as a normal file and tokenize it.
0

You may go for OpenCSV

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.