Java examples for Network:Network Address
parse host And Port via InetSocketAddress
//package com.java2s; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; public class Main { public static void main(String[] argv) throws Exception { String hostAndPort = "java2s.com"; System.out.println(parse(hostAndPort)); }/*www . j av a 2 s.co m*/ public static InetSocketAddress parse(String hostAndPort) throws UnknownHostException { String[] strings = hostAndPort.split(":"); return new InetSocketAddress(InetAddress.getByName(strings[0]), Integer.parseInt(strings[1])); } }