2

hi i am new to java.After so research about what i am facing, i try post to ask some question.

recently i am doing a text analyse software. and i try to get done with a 1*3 dimensional array. something like

[0]
   [][][]
[1]
   [][][]
[2] 
   [][][]
[3]
   [][][]

the three column in the second dimension of each is use for saving the details of the first dimension. but the second dimension array size is yet unknown which mean that, idont know how many i will find from the text that i am gonna search.it will increase once the target found. is this the stupid way for doing this. i know java can declare array like int [][] abc = new [5][]. but it just can declare only for one unknown dimension. then i try to do something like this

String [] abc = new string [4]

then i first make a presumption that the size is that in the first column in the second dimension.

abc[0] = String [10][][] inside1;
abc[1] = String [10][][] inside2;
abc[2] = String [10][][] inside3;
abc[3] = String [10][][] inside4;

but still getting error when i compile it.

how can i do the declaration or there got better to done this easy. if i miss any post in the internet about this. please show me any keyword or link for me to take a look.

1
  • That looks like a 4 by 3 (two-dimensional) array. Commented May 26, 2011 at 17:27

7 Answers 7

2

What is it that you are trying to implement? Sounds like you instead should use one of the collection classes together with value objects that represent your data.

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

1 Comment

yeah thanks for mention that.I think creating a new class to handle it will be better.
1

I think i understand what you are trying to do and its like this:

                String[][] value = new String[4][3];

Java doenst have multidimensional arrays, its Arrays Within Arrays.

Comments

0

If you're trying to parse a text file and you know what each column signifies, you should create a new object which contains that data. Arrays of arrays are an unnecessarily painful hack and your code is much more maintainable if you just do what Java is designed to be used for--write a class.

1 Comment

thanks for you comment, it inspire me.Yeah i should create a class for storing the data. i am new to programming especially OOP .So recently i am confusing with when to make it to a class or make it to a function. any book recommend to learn about that.
0

Example for a 10x13 matrix:

String [] [] abd = new String [10] [13];

EDIT: I chose 10x13, because 1x3 doesn't make much sense, being the first value 1.

4 Comments

sorry for the layout just now. i wanna doing is array in array. which mean in abd[0] got an three dimension array, abdinside[][][]. can i explain it clearly to you?
String [] [] [] [] abd = new String [] [] [] [];
forgot the dimensions: String [] [] [] [] abd = new String [dim1] [dim2] [dim3] [dim4];
thanks Hyper the code work will.din know that can declare some much dimension array.
0

Why don't you create an Object that has a 'name' property (or 'index' if you prefer), and a 'list' property of type List?

public class YourMultiDimensionalArrayObject {
    private int index;
    private List<String> vals;

    public YourMultiDimensionalArrayObject(int _index) {
        index = _index;
    }

    public void setValues(List<String> _vals) {
        vals = _vals;
    }

    public int getIndex() {
        return index;
    }

    public List<String> getVals() {
        return vals;
    }
}

Comments

0

You can use ArrayList to store an array of int values of unknown length. You can use an ArrayList> to store an indefinite number of int arrays.

Comments

0

I would create either a List<List<String>> or a Map<String, List<String>>, assuming the values you want to store and look-up by are Strings.

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.