forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
25 lines (16 loc) · 766 Bytes
/
Main.java
File metadata and controls
25 lines (16 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package modern.challenge;
import java.lang.reflect.Array;
public class Main {
public static void main(String[] args) {
int[] arrayOfInt = (int[]) Array.newInstance(int.class, 10);
Array.setInt(arrayOfInt, 0, 100);
int valueIndex0 = Array.getInt(arrayOfInt, 0);
System.out.println("At index 0 the value is: " + valueIndex0);
Class<?> stringClass = String[].class;
Class<?> clazz = arrayOfInt.getClass();
Class<?> typeInt = clazz.getComponentType();
Class<?> typeString = stringClass.getComponentType();
System.out.println("Type 'String[]': " + typeString.getName());
System.out.println("Type 'arrayOfInt': " + typeInt.getName());
}
}