3:02 pm - Monday January 16, 2017

Program for creating binary search empty list of data.

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

Program for creating binary search empty list of data

Example Program


import java.util.*;

public class Collections2 {

	public static void main(String args[]) {

		// create an empty list

		java.util.List<Object> emptylst = Collections.emptyList();

		System.out.println("Created empty immutable list: " + emptylst);

		// try to add elements

		emptylst.add("A");

		emptylst.add("B");

	}
}

 

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

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.