Here you can find the source of replace(List list, Object o, Object n)
Parameter | Description |
---|---|
list | the list to search |
o | which element to replace |
n | the element to replace the existing element with |
public static Object replace(List list, Object o, Object n)
//package com.java2s; /*// www . j av a 2 s .co m Copyright 1996-2010 Ariba, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. $Id: //ariba/platform/util/core/ariba/util/core/ListUtil.java#38 $ */ import java.util.List; public class Main { /** Replaces the element <b>o</b> with <b>n</b>. @param list the list to search @param o which element to replace @param n the element to replace the existing element with @return <b>o</b> if it was replaced or <b>null</b> if it was not found. @exception NullPointerException if <b>n</b> is <b>null</b> @aribaapi public */ public static Object replace(List list, Object o, Object n) { int index = list.indexOf(o); if (index != -1) { return list.set(index, n); } return null; } }