Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can you get array index?--b[4]...index=4?? 1

Status
Not open for further replies.

qb828

Programmer
Sep 27, 2000
98
US
hello!
how are you?
i must forgot..is there a method to get a index of array?
say if array[3], can it tell me index is 3?
i need a way to get that integer inside of []...


thanks

Q
 
There is a easy way to get the length of an array: use length. It will return the length of the array.

Greetings,
Steven.
 
thanks steven..
have Question about index array.
length gives integer of how many array there are.
i want to acess what a current array index is.

say int array[]=new int[3];
int c=array.length; //gives c=3, array size
array[2]; i want to acess index 2

can you do that?

Q
 
That depends on how you access it. To control the index of the array, you can use it within a for-loop, like

for(int index = 0; index < array.length; index++)
{
//do something with array[index];
}


But if you supply for example array[2] to a function, you'll loose the array, but get the primitive of the array back. So, in your example you'll only get an int, and have lost the position within the array.

Hope this helps,
Steven.
 
Before i forget, if you want to manipulate the array, you also can look to java.util.Arrays.
This class contains some functions for manipulating mainly primitive arrays.

Greetings,
Steven.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top