Hello, fellow programmers. Today I encountered a problem getting the 2d array length. By this I mean How many x values are filled, that all the x's sub values are filled {y}. ex
x-> 1, 2, 3 ,4, 5, 6
y 1, 1, 1
| 2, 2, 2
3, 3, 3
The code below always returns the arrayLength = 1, which with an already filled array it is supposed to be 5. This function is supposed to give me the last filled x value which in function getArrayLength() = c;
public static final int X_DIMENSION_SIZE = 4;
public static String[] lineByLine = new String[500];
public static String[][] lineByObject = new String[X_DIMENSION_SIZE][500];
public static int arrayLength = 1;
public static void testlength()
{
getArrayLength();
System.out.println(arrayLength);
}
public static void getArrayLength()
{
for(int c =1; c < 500; c++)
{
if(lineByObject[0][c] == null && lineByObject[1][c] == null && lineByObject[2][c] == null && lineByObject[3][c] == null)
{
arrayLength = c -1;
break;
}
}
}
Hope you can help me. And for extra information, I need this because I am writing info to a file line by line and storing them using delimiters and if I don't have the length of the array, after writing the filled values -> 123|Hello|Hi become -> ||| which would give me problems if I want to read the file.