9:16 am - Sunday March 26, 2017

Creating Program for how to get a fixed-size list backed by the specified array using static List method

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

This  Arrays Program for how to get a fixed-size list backed by the specified array using static <T> List<T> method

EXAMPLE PROGRAM


import java.util.*;

public class ArrayStatList {

	public static void main(String[] args) {

		String Ar[] = new String[] { "madhan", "sakthi", "karthi", "veeramani" };

		List<String> mad = Arrays.asList(Ar);

		System.out.println(mad);

	}
}

 

Output

[madhan, sakthi, karthi, veeramani]

Explanation

@SafeVarargs
public static <T> List<T> asList(T… a)

Returns a fixed-size list backed by the specified array. (Changes to the returned list “write through” to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray(). The returned list is serializable and implements RandomAccess.

This method also provides a convenient way to create a fixed-size list initialized to contain several elements:

   List<String> stooges = Arrays.asList(“Larry”, “Moe”, “Curly”);

Parameters:

a – the array by which the list will be backed

 

Returns:

a list view of the specified array

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.