在Java中,要输出数组的内存地址,可以使用 `System.identityHashCode()` 方法,该方法返回对象的唯一标识符,通常用于表示对象在堆中的地址。以下是如何使用 `System.identityHashCode()` 输出数组地址的示例:
int[] array = {1, 2, 3, 4, 5};
System.out.println("数组的内存地址(通过System.identityHashCode()): " + System.identityHashCode(array));
请注意,`System.identityHashCode()` 返回的是对象的哈希码,它可能不是数组的实际内存地址,因为哈希码是对象在内存中的位置的一个近似值。
另外,如果你需要更精确的内存地址,你可能需要使用Java的底层API,例如 `Unsafe` 类,但这通常不推荐,因为它可能导致不安全的操作和与平台相关的行为。