Posted By

narkisr on 07/16/08


Tagged

java collections


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

appx


Java Collection utilities


 / Published in: Java
 

This is a collection of useful static initializers of Java arrays, lists and maps.

  1. public class CollectionInitUtils {
  2.  
  3. public static <T> T[] ar(final T... ts) {
  4. return ts;
  5. }
  6.  
  7. public static <T> Set<T> set(final T... ts) {
  8. return new HashSet<T>(Arrays.asList(ts));
  9. }
  10.  
  11. public static <K, V> Map<K, V> zipMap(final K[] keys, final V[] values) {
  12. final Map<K, V> res = new HashMap<K, V>();
  13. for (int i = 0; i < keys.length; i++) {
  14. res.put(keys[i], values[i]);
  15. }
  16. return res;
  17. }
  18. }

Report this snippet  

You need to login to post a comment.