Java tutorial Array length
Java tutorial Array length
arrayName.length
For example, given the previous example, we can re-write it as,
public class ArraySample
{
public static void main( String[] args ){
int[] ages = new int[100];
for( int i=0; ifinal int ARRAY_SIZE = 1000; //declare a constant
. . .
int[] ages = new int[ARRAY_SIZE];
Java tutorial source code get input from keyboard
Java Tutorial Using JOptionPane to get input
Java tutorial Decision Control Structures: if statement
PHP Tutorial
Java programing source code sample printing characters
Java tutorial if-else statement
C programming sample source code: Sum of 2 numbers
Java Programming Features
In order to get the number of elements in an array, you can use the length field of an array. The length field of an array returns the size of the array. It can be used by writing,
arrayName.length
For example, given the previous example, we can re-write it as,
public class ArraySample
{
public static void main( String[] args ){
int[] ages = new int[100];
for( int i=0; i
- When creating for loops to process the elements of an array, use the array object's length field in the condition statement of the for loop. This will allow the loop to adjust automatically for different-sized arrays.
- Declare the sizes of arrays in a Java program using named constants to make them easy to change. For example,
. . .
int[] ages = new int[ARRAY_SIZE];
Related Post:
Java Tutorial switch statement source codeJava tutorial source code get input from keyboard
Java Tutorial Using JOptionPane to get input
Java tutorial Decision Control Structures: if statement
PHP Tutorial
Java programing source code sample printing characters
Java tutorial if-else statement
C programming sample source code: Sum of 2 numbers
Java Programming Features
Comments
Be the first to leave a comment!
About the Author
From Our Partners
People in Pictures
Top Geek Articles
|
Celebrities on the Phone
Cell phones are to celebrities like bats are to baseball: no one runs too far without them.
|
|
Why every guy should buy their girlfriend Wii Fit.
Gratuitous...
|
|
Hot Geeks -- The Sexiest Geeky Girls
These girls are gorgeous AND they'll play Warcraft with you. Doesn't get much better than that.
|




