1

I have a matrix of objects that contains data in this form:

name A,2,name B
name C,3,name D
name E,4,name F
name G,5,name H

My code to process the data is:

for (int i = 0; i < numRow; i++) {
    for (int j = 0; j < numColumn; j++) {
        Object o = matrix[i][j];
        String x = o.toString();
    }
}

In this way, x assumes these values in turn:

name A,
2,
name B,
name C,
3
name D,
name E,
...

and so on.

From the table I must create a linked list of objects Expression(String, int, String), for example:

Expression a = new Expression("name A", 2, "name B")

How could I extract the data from matrix in the right way to do this?

2
  • Next time why not try to solve it first and post your attempt rather than just throw your hands up and beg for a solution here. Commented Jun 23, 2012 at 14:21
  • I have tried to solve with no success obviously. Stackoverflow is for help in coding problems so... why this polemic?? -_-" Commented Jun 23, 2012 at 14:52

1 Answer 1

4

Do you mean something like this?

String[][] matrix = { 
        { "name", "2", "name" }, 
        { "name", "2", "name" },
        { "name", "2", "name" }, 
        { "name", "2", "name" }, 
};

List<Expression> list=new LinkedList<Expression>();
for (int i = 0; i < matrix.length; i++) 
    list.add(new Expression(matrix[i][0], Integer.parseInt(matrix[i][1]), matrix[i][2]));
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.