diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java new file mode 100644 index 0000000..a17a26a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4308.java @@ -0,0 +1,38 @@ +/* Listing4308.java */
+
+import java.lang.reflect.*;
+
+public class Listing4308
+{
+ public static void createArray1()
+ {
+ //Erzeugt ein eindimensionales int-Array
+ Object ar = Array.newInstance(Integer.TYPE, 3);
+ int[] iar = (int[])ar;
+ for (int i = 0; i < iar.length; ++i) {
+ iar[i] = i;
+ System.out.println(iar[i]);
+ };
+ }
+
+ public static void createArray2()
+ {
+ //Erzeugt ein zweidimensionales String-Array
+ Object ar = Array.newInstance(String.class, new int[]{7, 4});
+ String[][] sar = (String[][])ar;
+ for (int i = 0; i < sar.length; ++i) {
+ for (int j = 0; j < sar[i].length; ++j) {
+ sar[i][j] = "(" + i + "," + j + ")";
+ System.out.print(sar[i][j] + " ");
+ }
+ System.out.println();
+ };
+ }
+
+ public static void main(String[] args)
+ {
+ createArray1();
+ System.out.println("--");
+ createArray2();
+ }
+}
\ No newline at end of file |
