Java List Reverse firstElementOf(List list, int reverseIndexPosition)

Here you can find the source of firstElementOf(List list, int reverseIndexPosition)

Description

Returns the first element of a given List

License

Apache License

Parameter

Parameter Description
list a parameter
reverseIndexPosition a parameter

Declaration

public static <E> E firstElementOf(List<E> list, int reverseIndexPosition) 

Method Source Code

//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;
    }
}

Related

  1. addReverse(List list, List append)
  2. compareVersions(List list1, List list2)
  3. compareVersions(List version1, List version2)
  4. compareVersions(String version1, String version2)
  5. createReversedList(List inputList)
  6. formatToIp(final List shortList, final boolean reverseOrder)
  7. getReversedListIterable(final List inList)
  8. iterateReverse(final List elements)
  9. listToArrowSep(List strings, String highlightFirst, String highlightSecond, boolean reversed)