Solved

Basic Array Functions

Posted on 2006-11-20
6
185 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:vrameen
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17979101
>>How would I get the value of the "i" and the "j" into a variable (two seperate ones)?

i is an array
j is a variable

int[] row = arr[i];
int n = arr[i][j];
0
 

Author Comment

by:vrameen
ID: 17979217
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.

0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979238
vrameen,

Are you wanting the upperbound that the 2d array is filled in?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 86

Expert Comment

by:CEHJ
ID: 17979590
>>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;
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17980531
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;
        }
    }
}


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18037612
:-)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 134
simple java question 3 56
custom annotations 9 39
Java string replace 11 48
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question