如何通过Java的指针算法访问数组元素 [英] How to access array elements by pointer arithmetic in Java
本文介绍了如何通过Java的指针算法访问数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于在C以下声明,我可以申请'+'的地址和访问
其他元素。
Given the following declaration in C, I can apply '+' to the address, and access other elements.
char toto[5];
在换句话说,应用此操作符+
In other words, applying this operator +
toto+0x04
在Java中访问不同的数组元素。
Accesses a different array element in Java.
有没有用Java实现此操作的另一种方式?
Is there another way to implement this operation in java ?
非常感谢
推荐答案
如果我是正确的,你想在数组中的位置来访问的元素。你可以在Java中做到这一点。
If I'm right you want to access the element at that position in the array. You can do this in java.
char foo[] = new char[]{'1', '2','3','4', '5'};
char fooAtPositionFour = foo[4];
和分配新值是这样的:
foo[4] = 'x';
这篇关于如何通过Java的指针算法访问数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文