0

I got these arrays:

        String[] s0={"A","A","B","B","A","C"};

        String[] s11={"A","30"};
        String[] s12={"B","20"};
        List<String[]> l1=new ArrayList<String[]>();
        l1.add(s11);
        l1.add(s12);

        String[] s21={"B","10"};
        String[] s22={"B","20"};
        List<String[]> l2=new ArrayList<String[]>();
        l2.add(s21);
        l2.add(s22);

        String[] s31={"C","2"};
        String[] s32={"A","10"};
        String[] s33={"A","3"};
        List<String[]> l3=new ArrayList<String[]>();
        l3.add(s31);
        l3.add(s32);
        l3.add(s33);

        //result:
        String[] s1={"A","30","","10"};
        String[] s2={"A","","","3"};
        String[] s3={"B","20","10",""};
        String[] s4={"B","","20",""};
        String[] s5={"A","","",""};
        String[] s6={"C","","","2"};

The result should have 6 String Array, each String array should have 4 string corresponding to 4 columns: This is very tough,do u know how to do?

3
  • 1
    Why dont try 2d array? Commented Mar 31, 2013 at 14:21
  • You can use String.format("%-10s", yourStringAsParameter) in order to print the String in a 10 space block and left aligned. Commented Mar 31, 2013 at 14:21
  • The task here is to bring all the String Array s0,s11,s12,s21,s22,s31,s32,s33 into s1,s2,s3,s4,s5,s6 This is very tough Commented Mar 31, 2013 at 14:30

1 Answer 1

1

Considering the array s0 as your list for entries to the table (first column of Row), iterate each of them in the order. Your other 3 column values for each entry of s0 would be the value s0 element at Nth occurrence from among the Arrays in the lists. If there is no element at Nth occurrence then consider "" for column value. Every row formed would be an Array again with all column's values. You need to maintain the order of Arrays in List l1,l2 and l3. This is high-level logic to implement your requirement. Hope this would help.

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

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.