We Recommend

Java How to Program Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.


Posted By

narkisr on 07/16/08


Tagged

java collections


Versions (?)


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.