Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
Sep 12, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Java Arrays

C programmers are used to dealing with multidimensional arrays as chunks of contiguous memory which can be accessed through pointer arithmetic. In Java, an array is an actual object, and a multidimensional array must be constructed as a an array of arrays. It is an extremely convenient arrangement because you can access the length of an array from within the Java language, which allows you to make each array of a different length if necessary, without causing undue complications. But the downside is that you must explicitly instantiate each array, which is not as efficient as allocating one big chunk of memory. To create a 3x3x3 array of integers, you would do the following:

public final class Matrix {
  public static final void main(String[] args) {
    int i, j;
    int[][] matrix[];

    matrix = new int[3][][];

    for(i = 0; i < matrix.length; i++) {
      matrix[i] = new int[3][];
      for(j = 0; j < matrix[i].length; j++)
	matrix[i][j] = new int[3];
Daniel Savarese
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date