1 23 24 package com.sun.enterprise.util.collection; 25 26 import java.util.AbstractCollection ; 27 import java.util.ArrayList ; 28 import java.util.logging.Logger ; 30 import java.util.logging.Level ; 31 import com.sun.logging.LogDomains; 32 34 public class ContainerHelper 35 { 36 38 static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 40 public static String [] toStringArray(AbstractCollection coll) throws ArrayStoreException 42 { 43 String ss[] = new String [0]; 44 45 if(coll.size() > 0) 46 ss = (String []) coll.toArray(ss); 47 48 return ss; 49 } 50 51 53 public static ArrayList toArrayList(String [] ss) 54 { 55 if(ss == null) 56 return new ArrayList (); 57 58 ArrayList list = new ArrayList (ss.length); 59 60 for(int i = 0; i < ss.length; i++) 61 list.add(ss[i]); 62 63 return list; 64 } 65 66 68 public static String toOneString(String [] ss) 69 { 70 String s = new String (); 71 72 for(int i = 0; ss != null && i < ss.length; i++) 73 { 74 s += ss[i] + "\n"; } 76 return s; 77 } 78 79 81 public static void main(String [] args) 82 { 83 ArrayList L1 = new ArrayList (); 84 ArrayList L2 = new ArrayList (); 85 86 L1.add("Hello"); L1.add("World"); L1.add("!!!"); L2.add(new Integer (5)); 90 L2.add(new Integer (7)); 91 92 String ss[] = toStringArray(L1); 93 94 for(int i = 0; i < ss.length; i++) 95 _logger.log(Level.FINE,"String #" + i + ": " + ss[i]); 98 100 try 102 { 103 ss = toStringArray(L2); 104 } 105 catch(ArrayStoreException e) 106 { 107 _logger.log(Level.WARNING,"iplanet_util.arraystore_exception",e); 110 } 111 } 112 } 113 114 | Popular Tags |