Java Network Interface Get print(Collection objs)

Here you can find the source of print(Collection objs)

Description

print

License

LGPL

Declaration

public static <T> String print(Collection<T> objs) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.*;

import java.net.*;

import java.util.*;

public class Main {
    public static String print(Throwable t) {
        return printStackTrace(t);
    }//from   w w w  .  j  a va  2  s  . c  o m

    public static <T> String print(Collection<T> objs) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (T obj : objs) {
            if (first)
                first = false;
            else
                sb.append(", ");
            sb.append(obj);
        }
        return sb.toString();
    }

    public static <T> String print(Map<T, T> map) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (Map.Entry<T, T> entry : map.entrySet()) {
            if (first)
                first = false;
            else
                sb.append(", ");
            sb.append(entry.getKey()).append("=").append(entry.getValue());
        }
        return sb.toString();
    }

    public static String print(List<NetworkInterface> interfaces) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;

        for (NetworkInterface intf : interfaces) {
            if (first) {
                first = false;
            } else {
                sb.append(", ");
            }
            sb.append(intf.getName());
        }
        return sb.toString();
    }

    /**
     * Use with caution: lots of overhead
     */
    public static String printStackTrace(Throwable t) {
        StringWriter s = new StringWriter();
        PrintWriter p = new PrintWriter(s);
        t.printStackTrace(p);
        return s.toString();
    }
}

Related

  1. getUsualNetworkInterfaces()
  2. isActive(String niName)
  3. isNixMashPC()
  4. parseInterfaceList(String s)
  5. pingFromInterface(String name)
  6. printValidInterfaces(PrintWriter pout)
  7. toNI(String niName)