1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* Create List from Java Object Array Example This java example shows how to create a List from an array of type Object using asList method of Arrays class. */ import java.util.Arrays; import java.util.List; import java.util.Iterator; public class CreateListFromObjectArrayExample { public static void main(String[] args) { //create an array of type Object, in this case we will create String array String[] strArray = new String[]{"Object","Array","Converted","To","List"}; /* To create List from an array of type Object use, static List asList(Object[] objArray) method of Arrays class. This method returns a fixed sized list backed by original array. */ List list = Arrays.asList(strArray); //get an iterator Iterator itr = list.iterator(); //iterate through list created from Array System.out.println("List created from an Array of type Object contains,"); while(itr.hasNext()) System.out.println(itr.next()); } } /* Output would be List created from an Array of type Object contains, Object Array Converted To List */ |
Great, l love you!
the import java.util.Arrays; is having an error….does that mean that the computer im using doesnt have an array to import????? need reply asap….please
Try-
import java.util.*;
,,pigaw inyo mga program ka common na sa amon nga mga programmer… please try to have another examples tnx..
Best site I have see for java examples.
Does anybody have an example of how to do this without using any methods, basically doing it with loops and manually.