Link to home
Start Free TrialLog in
Avatar of vrameen
vrameen

asked on

Basic Array Functions

Hi,

I would like to know how to get the value of the position of the array..

E.g.
arr[i][j]

How would I get the value of the "i" and the "j" into a variable (two seperate ones)?

Note I don't want to know what the [i][j] have been assigned, but rather than the actual numerical value of "i" and "j"...

Thanks
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vrameen
vrameen

ASKER

I don't really understand..

To clarify my question...

arr[i][j] is a 2d array...

Say the array is now at arr[3][12] and arr[3][12] = "hello";
I want to get the number "3" and the number "12" into two separate variables..
I'm not interested in getting the string "hello", but rather the array numbers into the variable.

vrameen,

Are you wanting the upperbound that the 2d array is filled in?
>>but rather the array numbers into the variable.

But they're already in variables i and j ..?

You can of course copy them

int x = i;
int y = j;
If you are looking for the position where the array value is "hello", you can search for it

int x = -1;
int y = -1;

for(int i=0; i<arr.length; i++) {
    for(int j=0; i<arr[i].length; j++) {
        if("hello".equals(arr[i][j])) {
            x = i;
            y = j;
            break;
        }
    }
}


:-)