socket应用示例
在使用中,都用约定使用数据的传输格式等等。见代码Socket socket = new Socket();//new a socket clientSocketAddress host = new InetSocketAddress(InetAddress.getLocalHost(),5678);socket.connect(host);//to connect the hostsocket.setSoTimeout(60000);//设置成60秒PrintWriter out=new PrintWriter(socket.getOutputStream());//获得输出流,写入请求信息out.print(functionCode+len+cardInfo+'');out.flush();//一定要有BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));//获得服务器
关于hashmap的遍历问题
听我们的支持说遍历hashmap使用entryset快些,因大部分都是用keyset遍历的,也没有去想那么多。今天研究了一下,果然差了很多。见示例,只是简单的hashmap信息。不多说了,大家把这个类在本地运行下,很容易看到结果。import java.util.HashMap;import java.util.Iterator;import java.util.Calendar;public class HashMapTest {public static void main(String[] args) {HashMap hashmap = new HashMap();for(int i=0;i<1000;i++){hashmap.put(""+i,"hello");}long bs = Calendar.getInstance().getTimeInMillis(