Hey, is there any way to pass a value to a object and then use it as the dimension for a Member Variable Array.
Basically I want to be able to pass a integer to a object on its creation, and then use it as the dimension value for an array that can be accessed by all of the method within that class.
Or is there some way to make an Array declared inside a method or constructor global to all methods within that class?
Like the below code...
public class TestExample { long some_array[][]; public TestExample(int some_int){ some_array[][] = new long[some_int][4]; } }
--- Update ---
I still interesting if there is a simple way to do this and have just one array... but I just solved it by using 3 ArrayLists and then writing methods so they act like one big array.
import java.util.ArrayList; public class Files { long somearray[][]; ArrayList<Long> listid = new ArrayList<Long>(); ArrayList<Long> listamount = new ArrayList<Long>(); ArrayList<Long> listdownloded = new ArrayList<Long>(); public Files(){ } public void setmap(int x, int y, long value){ if (y == 0){ if (listid.contains(x)){ listid.set(x, value); } else listid.add(value); } if (y == 1){ if (listamount.contains(x)){ listamount.set(x, value); } else listamount.add(value); } if (y == 2){ if (listdownloded.contains(x)){ listdownloded.set(x, value); } else listdownloded.add(value); } } public long map(int x, int y){ long fail = -1; if (y == 0){ return listid.get(x); } else if (y == 1){ return listamount.get(x); } else if (y == 2){ return listdownloded.get(x); } return fail; } public int maplength(){ return listid.size(); } }