Link to home
Start Free TrialLog in
Avatar of vgsrikanth
vgsrikanth

asked on

Reading csv file and storing it in HashMap

Hi, I have a csv file which is of the following format. I want to store it in a HashMap.

Name,CategoryName,C1.UserName,C1.PWD,#,CategoryName,C2.Applied,C2.CTN,#
Charlie,C1                  ,U1                 ,P1         ,  ,C2                    ,A1             ,N1       , ,
Mark   ,C1                  ,U2                 ,P2         ,  ,C2                    ,A2              ,N2      , ,

I want to store the all the values for a particular category C1 that is C1.user name and c1.pwd

Thank you.
Avatar of Am P
Am P
Flag of India image

You can use a List & HashMap combination. HashMap will be used to store an entire row in a column/value pair, while List will be used to store the entire CSV (all HashMap object).

Map (
Name=Charlie
CategoryName=C1
C1.UserName=U1
C1.PWD=P1
# (Number)=null
CategoryName=C2
C2.Applied=A1
C2.CTN=N1
# (Number)=null
)

Hope this works for you.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vgsrikanth
vgsrikanth

ASKER

Yes  CEH, I want to store C1 category values in a seperate list or hashmap, c2 in a seperate list.
Actually it looks to me like you'd be much better off with a List<UserInfo> where UserInfo is a bean containing username and password pairs
CEHJ, can you give me the code if you dont mind.thank u.
Start by writing the bean class and posting it here and i'll help you with the rest. Make sure it has a two-arg ctor (username and password)