Here you can find the source of parseCommaDelimitedHosts2(String hosts, int port_range)
public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range)
//package com.java2s; //License from project: LGPL import java.net.*; import java.util.*; public class Main { /**//from w w w .j av a 2 s.c om * Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of * InetSocketAddress */ public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) { StringTokenizer tok = new StringTokenizer(hosts, ","); String t; InetSocketAddress addr; Set<InetSocketAddress> retval = new HashSet<InetSocketAddress>(); while (tok.hasMoreTokens()) { t = tok.nextToken().trim(); String host = t.substring(0, t.indexOf('[')); host = host.trim(); int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']'))); for (int i = port; i < port + port_range; i++) { addr = new InetSocketAddress(host, i); retval.add(addr); } } return Collections.unmodifiableList(new LinkedList<InetSocketAddress>(retval)); } }