Java examples for Collection Framework:Array Convert
Converts collection to a string array by calling toString on each member.
//package com.java2s; import java.util.Collection; public class Main { public static void main(String[] argv) { Collection collection = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(java.util.Arrays .toString(toStringArray(collection))); }//from w ww. j ava2s. c om /** * Converts collection to a string array by calling toString on each member. * * @param collection collection to convert * @return string array */ public static String[] toStringArray(Collection collection) { String[] stringArray = new String[collection.size()]; int i = 0; for (Object string : collection) { stringArray[i++] = string.toString(); } return stringArray; } }