Here you can find the source of replace(List
Parameter | Description |
---|---|
list | a parameter |
from | a parameter |
to | a parameter |
public static <T> T replace(List<T> list, T from, T to)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.List; import java.util.Map; public class Main { /*****//from www .j ava 2 s .c o m * Replace an item with another item for the list * * @param list * @param from * @param to * @return */ public static <T> T replace(List<T> list, T from, T to) { if (isEmpty(list)) return null; if (!list.contains(from)) return null; int index = list.indexOf(from); list.set(index, to); return to; } public static boolean isEmpty(Iterable<?> i) { if (i instanceof Collection) return ((Collection<?>) i).isEmpty(); return i == null || !i.iterator().hasNext(); } public static boolean isEmpty(Map<?, ?> p_oCol) { return p_oCol == null || p_oCol.isEmpty(); } }