DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

arraycopy将数组分为两部分时游标的设置方法


System.arraycopy是复制数组的一个常用工具,它在游标处如何分为两个是一个需要注意的问题,例如下面的示例代码:

byte [] src = { 104, 101, 108, 108, 111 };

int endPos = 2;

byte [] dest = new byte [endPos];

byte [] surplus = new byte [src. length - endPos];

System. arraycopy (src, 0, dest, 0, dest. length );

System. arraycopy (src, endPos, surplus, 0, src. length - endPos);

游标(变量endPos)位置为2时,dest数组是{104, 101},surplus数组是{108, 108, 111}。

也就是说,编号为游标的元素(从0开始编号)在原数组分割后变为后面数组的第一个元素。



Published

Aug 10, 2010

Last Updated

Aug 10, 2010

Category

Tech

Tags

  • arraycopy 2
  • Java 106
  • 数组 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor