Java: 判断是否为Array数组

package com.company;


public class Wig{
  public static void main(String[] args){
    Object[] objects = new String[]{"a", "b", "c"};
    if(objects instanceof String[]){
      String[] strings = (String[]) objects;
      for(String string : strings){
        System.out.println("string = " + string);
      }
    }

    if(objects == null){
      throw new NullPointerException(String.format("%s is null", objects));
    }

    System.out.println("objects.getClass().isArray() = " + objects.getClass().isArray());
  }
}

 

posted @ 2022-04-12 13:36  ascertain  阅读(599)  评论(0编辑  收藏  举报