I am a new java programmer.At the beginning,i write a method convert Integer List to int[] in my project
public int[] convertToArray(List<Integer> list) { int[] array = new int[list.size()]; for (int i = 0; i < list.size(); i++) { array[i] = list.get(i); } return array; }
Been there many times. Have spent hours to write a piece of logic only to find it has been already implemented through a library.
One thing you could do is to google what you are trying to achieve if you are about to write any utility function like the one in your question. Most likely you would find a library or two.
Another way would be to read the documentation of famous libraries like Apache Commons, Guava etc.
There aren't any easier ways.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.