Home java Dynamic JAVA Array

Dynamic JAVA Array

Author

Date

Category

In C++, a dynamic array in a class was described as follows:

class YepYep {
private: int ** array;
public: YepYep {
array = new int * [50];
for (int i = 0; i & lt; 50; i ++)
  array [i] = new int [50];};

How to allocate an array in Java for the class to be used in the class methods according to the same principle.


Answer 1, authority 100%

Fixed:

public class Jaba {
  private int [] [] x;
  public Jaba () {
    x = new int [50] [50]; // no one bothers to declare without a constructor
  }
}

Dynamic and slightly larger than just an array

public class Jaba {
  private List & lt; Integer & gt; x = new ArrayList ();
}

Answer 2

might this work?

create

public String [] [] readingDataCsv = new String [1000] [1000];

filling

readingDataCsv [i] [0] = parts [0];

read

// select row number3 and column number2
 System.out.println ("--- readingParts -" + readingDataCsv [0] [0] + "|" + readingDataCsv [0] [1] + "--------");

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions