int[int]’用作数组下标类型无效
时间: 2023-05-25 19:02:37 浏览: 76
这是因为数组下标必须是整数类型,而`int[int]`不是整数类型。
`int[int]`表示一个从整数到整数的映射,它并不能直接作为数组下标使用。如果你想使用它作为数组下标,你需要想办法将它转换为整数类型。
例如,可以使用哈希函数将`int[int]`转换为整数,然后使用该整数作为数组下标。具体实现可以参考哈希表的设计。
相关问题
如何对int*类型的数组进行操作
您可以使用指针来访问 int 数组中的元素。如要修改 int 数组中的某个元素,您可以通过以下方式之一来进行操作:
1. 使用指针访问数组元素,如:*(arr+idx) = val;
2. 直接使用数组下标访问数组元素,如:arr[idx] = val。
其中,arr 表示 int 类型的数组,idx 表示要访问的数组元素下标,val 表示要修改为的值。
java int数组转integer数组
Java中,int数组可以通过循环遍历,将每个元素转换为Integer类型,然后存储到一个新的Integer数组中。
示例代码如下:
```
int[] intArray = {1, 2, 3, 4, 5};
Integer[] integerArray = new Integer[intArray.length];
for (int i = ; i < intArray.length; i++) {
integerArray[i] = Integer.valueOf(intArray[i]);
}
```
首先定义一个int类型的数组intArray,然后定义一个与intArray长度相同的Integer类型的数组integerArray。
通过for循环遍历intArray数组,将每个元素转换为Integer类型,并存储到integerArray数组中。
最终得到的integerArray数组就是将int数组转换为Integer数组的结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)