Here you can find the source of arrayElement(T[] array, int index)
Parameter | Description |
---|---|
T | the array type. |
array | the array to use. |
index | the index to use. |
array[index]
or null if out of bounds.
public static <T> T arrayElement(T[] array, int index)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009-2016 Black Rook Software * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html ******************************************************************************/ public class Main { /**//from w w w.j av a 2 s .c o m * Gets the element at an index in the array, but returns * null if the index is outside of the array bounds. * @param <T> the array type. * @param array the array to use. * @param index the index to use. * @return <code>array[index]</code> or null if out of bounds. * @since 2.31.2 */ public static <T> T arrayElement(T[] array, int index) { if (index < 0 || index >= array.length) return null; else return array[index]; } }