目录

static void setByte(Object array, int index, byte b)

描述 (Description)

java.lang.reflect.Array.setByte(Object array, int index, byte value)方法将指定数组对象的索引组件的值设置为指定的字节值。

声明 (Declaration)

以下是java.lang.reflect.Array.setByte(Object array, int index, byte value)方法的声明。

public static void setByte(Object array, int index, byte value)
   throws IllegalArgumentException, ArrayIndexOutOfBoundsException

参数 (Parameters)

  • array - 数组。

  • index - 索引。

  • value - 索引组件的新值。

异常 (Exceptions)

  • NullPointerException - 如果指定的对象参数为null。

  • IllegalArgumentException - 如果指定的对象参数不是数组,或者数组组件类型是原始的并且解包转换失败。

  • ArrayIndexOutOfBoundsException - 如果指定的index参数为负数,或者它大于或等于指定数组的长度

例子 (Example)

以下示例显示了java.lang.reflect.Array.setByte(Object数组,int索引,字节值)方法的用法。

package com.iowiki;
import java.lang.reflect.Array;
public class ArrayDemo {
   public static void main(String[] args) {
      byte[] array = new byte[]{1,2, 3};
      Array.setByte(array, 0, (byte)2);
      Array.setByte(array, 1, (byte)3);
      Array.setByte(array, 2, (byte)4);
      System.out.println("array[0] = " + Array.getByte(array, 0));
      System.out.println("array[1] = " + Array.getByte(array, 1));
      System.out.println("array[2] = " + Array.getByte(array, 2));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

array[0] = 2
array[1] = 3
array[2] = 4
↑回到顶部↑
WIKI教程 @2018