Results 1 to 1 of 1
-
Converting a Collection to an Array
Java Code:import java.util.ArrayList; import java.util.Collection; public class PlanetSet { public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; Collection planets = new ArrayList(); for (int i = 0, n = names.length; i < n; i++) { planets.add(names[i]); } String s[] = (String[]) planets.toArray(new String[0]); for (int i = 0, n = s.length; i < n; i++) { System.out.println(s[i]); } planets.remove(names[3]); System.out.println(names[1] + " " + planets.contains(names[1])); System.out.println(names[3] + " " + planets.contains(names[3])); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Converting array to list and sorting it
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:36 PM -
Converting an Array to a Vector
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:44 PM -
Converting ArrayList to Array
By Java Tip in forum Java TipReplies: 0Last Post: 11-13-2007, 10:41 AM -
Problems with collection
By Heather in forum New To JavaReplies: 1Last Post: 07-08-2007, 12:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks