Here you can find the source of firstElementOf(List
Parameter | Description |
---|---|
list | a parameter |
reverseIndexPosition | a parameter |
public static <E> E firstElementOf(List<E> list, int reverseIndexPosition)
//package com.java2s; /******************************************************************************* * Copyright 2011 Danny Kunz/*w w w. j a v a 2s . co m*/ * * 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. ******************************************************************************/ import java.util.List; public class Main { /** * Returns the first element of a given {@link List} * * @param list * @param reverseIndexPosition * @return */ public static <E> E firstElementOf(List<E> list, int reverseIndexPosition) { return list != null && !list.isEmpty() ? list.get(0) : null; } /** * Returns the element at the given index position within the given {@link List} instance. <br> * <br> * If the given {@link List} is null, null is returned. <br> * If the index is out of bounds, null is returned. * * @see #elementAt(List, int) * @param list * {@link List} * @param index * @return element at the specific index position */ public static <E> E get(List<E> list, int index) { E retval = null; if (list != null && index >= 0 && index < list.size()) { retval = list.get(index); } return retval; } }