Java Collection utilities


/ Published in: Java
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.