提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在列表中上移对象
//package com.nowjava; /* N o w J a v a . c o m */ 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(moveUp(list, o)); } @SuppressWarnings("unchecked") public static boolean moveUp(List list, Object o) { int index = list.indexOf(o); if (index >= 0) {/*来自 nowjava*/ try { Object temp = list.set(index - 1, o); list.set(index, temp); return true;