Java tutorial
//package com.java2s; import java.io.IOException; import java.io.Writer; import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; public class Main { private static String newLine = System.getProperty("line.separator"); public static void writeToWriter(Collection s, Writer out) throws IOException { writeToWriter(s.iterator(), out); } public static void writeToWriter(List l, Writer out) throws IOException { writeToWriter(l.iterator(), out); } public static void writeToWriter(Enumeration enumList, Writer out) throws IOException { while (enumList.hasMoreElements()) { out.write(enumList.nextElement().toString()); out.write(newLine); } out.flush(); } public static void writeToWriter(Iterator it, Writer out) throws IOException { while (it.hasNext()) { out.write(it.next().toString()); out.write(newLine); } out.flush(); } public static void writeToWriter(Map m, Writer out) throws IOException { writeToWriter(m.entrySet().iterator(), out); } }