Java examples for Collection Framework:List
move Object Up in the List
//package com.java2s; import java.util.List; public class Main { public static void main(String[] argv) throws Exception { List list = java.util.Arrays.asList("asdf", "java2s.com"); Object o = "java2s.com"; System.out.println(moveUp(list, o)); }/*from w w w. j a v a2 s.c o m*/ @SuppressWarnings("unchecked") public static boolean moveUp(List list, Object o) { int index = list.indexOf(o); if (index >= 0) { try { Object temp = list.set(index - 1, o); list.set(index, temp); return true; } catch (IndexOutOfBoundsException e) { return false; } } return false; } }