Description

first Boolean

License

Apache License

Declaration

public static <A> Boolean firstBoolean(List<A> list) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2012 Apigee Corporation//from w  w  w. j a v a  2 s . 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 {
    public static <A> Boolean firstBoolean(List<A> list) {
        A a = first(list);
        if (a == null) {
            return null;
        }
        if (a instanceof Boolean) {
            return (Boolean) a;
        }
        try {
            return Boolean.parseBoolean((String) a);
        } catch (Exception e) {
        }
        return null;
    }

    public static <A> A first(List<A> list) {
        if (list == null) {
            return null;
        }
        if (list.size() == 0) {
            return null;
        }
        return list.get(0);
    }
}

Related

  1. first(List list)
  2. first(List list)
  3. first(List list)
  4. first(List list)
  5. first_nItems(int n, Collection fromList)
  6. firstColumnRemovable(List data)
  7. firstElement(List list)
  8. firstItem(Iterable list)
  9. firstItem(List items)