Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {
    public static <T> T first(List<T> list) {
        return get(list, 0);
    }

    public static <T> T get(List<T> list, int index) {
        if (index < 0) {
            throw new IndexOutOfBoundsException("Index cannot be negative: " + index);
        }
        if (list == null || index > list.size() - 1) {
            return null;
        }
        return list.get(index);
    }
}