Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

How to convert generic list to array: List to Long[] Array???

Posted by Pankil Patel on April 8, 2011

How to convert generic list to array: List<Long> to Long[] Array???

Main point in this question is to pass one argument (fixed length empty array of specific object type) to “toArray” method of  “Collection” interface.

public static void main(String[] args) {

A a = new A();

List<Long> longList = new ArrayList<Long>();
longList.add(23l);
longList.add(2l);
longList.add(3l);

a.setArrayLong((Long[])longList.toArray(new Long[longList.size()]));

}

public class A {

private Long[] arrayLong;

public Long[] getArrayLong() {
return arrayLong;
}

public void setArrayLong(Long[] arrayLong) {
this.arrayLong = arrayLong;
}

}

Advertisements

One Response to “How to convert generic list to array: List to Long[] Array???”

  1. Johnc820 said

    Thanks so much for sharing this excellent info! I’m seeking forward to see much more posts! ecfcaegbbeek

Leave a Reply

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 / Change )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
%d bloggers like this: