Created
November 25, 2011 13:53
-
-
Save freewind/1393582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Array; | |
import java.util.Arrays; | |
import java.util.Date; | |
public class TestArr { | |
public static <T> T[][] createArray(int rows, int cols, T init) { | |
T[] row = (T[]) Array.newInstance(init.getClass(), cols); | |
Arrays.fill(row, init); | |
T[][] result = (T[][]) Array.newInstance(row.getClass(), rows); | |
Arrays.fill(result, row); | |
return result; | |
} | |
public static void main(String[] args) { | |
int rows = 2; | |
int cols = 8; | |
Date[][] arr = createArray(rows, cols, new Date()); | |
for (int i = 0; i < rows; i++) { | |
for (int j = 0; j < cols; j++) { | |
Date item = arr[i][j]; | |
System.out.println(item); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment