0

@ Gouki Pls check if this is a correct Implementation as there may be multiple attributes in my row that has T,N or X -I basically want to check if the first attribute in every row for a value of T,N or X and do some business logic- Thanks

public void printarray(List<String[]> usersList)     {  
  for(String[] row: usersList) {

      System.out.println(row[0]);

if(row[0].equals("N")){
System.out.println("Insert records in DB");
System.out.println("*********************");
System.out.println(row[1]+" , " + row[2]+" , "+row[3]+" , " + row[4]+" " +row[5]);
}
     if(row[0].equals("T")){
System.out.println("Get date from DB and update DB based on the same");
System.out.println("*********************");
System.out.println(row[1]+" , " + row[2]+" , "+row[3]+" , " + row[4]+" " +row[5]);
}
     if(row[0].equals("X")){
System.out.println("Update 2 sub tables");
System.out.println("*********************");
System.out.println(row[1]+" , " + row[2]+" , "+row[3]+" , " + row[4]+" " +row[5]);
}

}
}

1 Answer 1

4

You can perhaps use a List as container for every row (which is an array).

List<String[]> userList = new ArrayList<String[]>();

and then on your while loop:

  while ((line = br.readLine()) != null) {
        String[] values = line.split(",");
        userList.add(values);
  }

To retrieve, modify your printarray :

public void printarray(List<String[]> usersList)
    {

        for(String[] row: usersList) {
            for(String element:row) {
                System.out.println(element);
            }
        }
        System.out.println();

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

9 Comments

Why don't you put values directly into userList?
Also consider List<List<String>>.
@marcelo, you're right, i overlooked that. Will update answer
@ In ur updated answe pls help me with populating in userlist itself and retrieving it as well Thanks a lot for your help
@user549432 , I've updated the answer to demonstrate how to retrieve the data from the list. It functions just the same as your original method (print the elements)
|

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.