Java實現從IP和埠列表List獲取分離的IP和埠值

鍾超發表於2011-11-17

List<String> addrList = getFromSomeWhere();
InetSocketAddress[] addrs = new InetSocketAddress[addrList.length()];
for (int i = 0; i < addrList.length(); ++i) {
	String[] parts = addrList.get(i).split("\\:", 2);
	if (parts.length != 2) {
		// Your code for tackling this error.
	}
	addrs[i] = new InetSocketAddress(part[0].trim(), part[1].trim());
}


相關文章