collections and array   Leave a comment

// Create an array containing the elements in a list

Object[] objectArray = list.toArray();

MyClass[] array = (MyClass[])list.toArray(new MyClass[list.size()]);

// Create an array containing the elements in a set

objectArray = set.toArray();

array = (MyClass[])set.toArray(new MyClass[set.size()]);

// Create an array containing the keys in a map

objectArray = map.keySet().toArray();

array = (MyClass[])map.keySet().toArray(new MyClass[set.size()]);

// Create an array containing the values in a map

objectArray = map.values().toArray();

array = (MyClass[])map.values().toArray(new MyClass[set.size()]);

// Fixed-size list

List list = Arrays.asList(array);

// Growable list

list = new LinkedList(Arrays.asList(array));

// Duplicate elements are discarded

Set set = new HashSet(Arrays.asList(array));

Posted 2010年12月2日 by gw8310 in 未分类

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: