Here you can find the source of get(T[] array, int index)
Returns the value at the given index in the arrayor null if the index is out of bounds.
Parameter | Description |
---|---|
array | the array |
index | the index |
public static <T> T get(T[] array, int index)
//package com.java2s; //License from project: LGPL import java.util.*; public class Main { /**//from w w w.j a v a2 s . c o m * <p>Returns the value at the given index in the arrayor null if the index is out of bounds.</p> * @param array the array * @param index the index * @return the element at index {@code index} or null */ public static <T> T get(T[] array, int index) { return index >= 0 && index < array.length ? array[index] : null; } /** * <p>Returns the value at the given index in the array or {@code defaultValue} if the index is out of bounds.</p> * @param array the array * @param index the index * @param defaultValue the default value * @return the element at index {@code index} or the default value */ public static <T, D extends T, R extends T> T get(R[] array, int index, D defaultValue) { return index >= 0 && index < array.length ? array[index] : defaultValue; } /** * <p>Returns the value at the given index in the List or null if the index is out of bounds.</p> * @param list the List * @param index the index * @return the element at index {@code index} or null */ public static <T> T get(List<T> list, int index) { return index >= 0 && index < list.size() ? list.get(index) : null; } /** * <p>Returns the value at the given index in the List or {@code defaultValue} if the index is out of bounds.</p> * @param list the List * @param index the index * @param defaultValue the default value * @return the element at index {@code index} or the default value */ public static <T, D extends T, V extends T> T get(List<V> list, int index, D defaultValue) { return index >= 0 && index < list.size() ? list.get(index) : defaultValue; } }