Here you can find the source of singletonList(T element)
null
.
Parameter | Description |
---|---|
T | the type of the element in the list. |
element | the element. |
public static <T> List<T> singletonList(T element)
//package com.java2s; /*/*from www . jav a2 s . co m*/ * $Id$ * * SARL is an general-purpose agent programming language. * More details on http://www.sarl.io * * Copyright (C) 2014-2016 the original authors or authors. * * 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.Collections; import java.util.List; public class Main { /** Replies a singleton list with the given element, or the empty list if * the element is <code>null</code>. * * @param <T> the type of the element in the list. * @param element the element. * @return the list with the element, or the empty list. */ public static <T> List<T> singletonList(T element) { if (element == null) { return Collections.emptyList(); } return Collections.singletonList(element); } }