Java Collection First getFirst(Collection collection)

Here you can find the source of getFirst(Collection collection)

Description

get First

License

Apache License

Declaration

public static <T> T getFirst(Collection<T> collection) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005, 2014 //from   w w  w.j a  va2s. co  m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/

import java.util.Collection;

import java.util.List;

public class Main {

    public static <T> T getFirst(Collection<T> collection) {
        if (isEmpty(collection)) {
            return null;
        }
        if (collection instanceof List) {
            return ((List<T>) collection).get(0);
        }
        return collection.iterator().next();
    }

    public static boolean isEmpty(Collection<?> collection) {
        return (collection == null) || collection.isEmpty();
    }
}

Related

  1. getFirst(Collection collection)
  2. getFirst(Collection collection)
  3. getFirst(Collection collection)
  4. getFirst(Collection collection)
  5. getFirst(Collection collection)
  6. getFirst(Collection l)
  7. getFirst(Collection set)
  8. getFirst(Collection set, boolean remove)
  9. getFirst(Collection ts)