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.
Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
Am P

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
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
vgsrikanth

ASKER
Yes  CEH, I want to store C1 category values in a seperate list or hashmap, c2 in a seperate list.
CEHJ

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
vgsrikanth

ASKER
CEHJ, can you give me the code if you dont mind.thank u.
CEHJ

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)