提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在列表中下移对象
/* *来 自 n o w j a v a . c o m */ //package com.nowjava; import java.util.List; public class Main { public static void main(String[] argv) throws Exception { List list = java.util.Arrays.asList("asdf", "nowjava.com"); Object o = "nowjava.com"; System.out.println(moveDown(list, o)); } @SuppressWarnings("unchecked") public static boolean moveDown(List list, Object o) { int index = list.indexOf(o); if (index >= 0) { try {/** 时代Java - N o w J a v a . c o m 提 供 **/ Object temp = list.set(index + 1, o); list.set(index, temp); return true;