Collection static final List emptyList() method Example Program


Returns the empty list (immutable). 

Program

package com.candidjava;

import java.util.*;

/**
 * 
 * @author karthikeyan.T
 * @description The following example shows the usage of Collections.emptyList()
 */

public class EmptyList {

	public static void main(String args[]) {
		List emptylst = Collections.emptyList();
		System.out.println("Created empty immutable list: " + emptylst);
	}
}

Output

Created empty immutable list: []

Explanation

public static final <T> List<T> emptyList()
Returns the empty list (immutable). This list is serializable.
This example illustrates the type-safe way to obtain an empty list:
     List<String> s = Collections.emptyList();
 
Implementation note: Implementations of this method need not create a separate List object for each call. Using this method is likely to have comparable cost to using the like-named field. (Unlike this method, the field does not provide type safety.)
Since:
1.5
See Also:
EMPTY_LIST


Related Post

Comments


©candidjava.com