提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
数组中最后一个非空对象的索引。
/**from 时代Java**/ //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { Object[] objects = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; System.out.println(lastNonNullValueIndex(objects)); } /** * Index of last last not null object. * * If objects is null or all objects values are null returns -1; * * @param objects * @return */ public static int lastNonNullValueIndex(final Object[] objects) { int i = -1; if (objects != null) {/*from nowjava*/ for (i = objects.length - 1; i >=