0

I don't know, if I forgot how, or I just can't figure it out how.

For example :

        Object[][] data = {
            {"id", "projectname","valueid", "value"},
        };

And this is how they should be added, but in loop:

        Object[][] data = {
            {"id", "projectname","valueid", "value"},
            {"id2", "projectname2","valueid2", "value2"},
            {"id3", "projectname3","valueid3", "value3"},
        };

And so on..

I need a tip only, like a skeleton how it should be. I tried to figure it out, but had no idea how.

Thanks!

6
  • 1
    Have you tried googleing "java arrays"? Commented Aug 29, 2017 at 11:05
  • @xander yes, got some information about that, but still not enough. Commented Aug 29, 2017 at 11:06
  • homeandlearn.co.uk/java/multi-dimensional_arrays.html Commented Aug 29, 2017 at 11:06
  • can you please elaborate what you exactly want know? Commented Aug 29, 2017 at 11:07
  • Whats wrong with using a hashmap for this if you need to store the keys? Commented Aug 29, 2017 at 11:08

2 Answers 2

4

You can add a new array to another array like this :

data[1] = new Object[]{"id_1", "projectname_1","valueid_1", "value_1"};
...
data[n] = new Object[]{"id_n", "projectname_n","valueid_n", "value_n"};

You can use this way in any loop for example :

int length = 5;
Object[][] data = new Object[length][];
for(int i = 0; i < length; i++){
    data[i] = new Object[]{...some information};
}
Sign up to request clarification or add additional context in comments.

Comments

1
for (int i = 1; i < data.length; i++) {
    for (int j = 0; j < data[i].length; j++) {
        int line = i+1;
        data[i][j] = data[0][j]+ line;
    }
}

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.