List uses
List lst = new ArrayList ();//list is an interface, ArrayList is an implementation class
List.add ("Hello");//Add
List.removeat (0);//delete
List.get (0);//Acquired
Int32[] Vals = (int32[]) List.toarray (typeof (Int32));//convert to an array
String[] attr = (string[]) List.toarray (new String[list.size ()]);//
Traversing a foreach
list<string> lst = new arraylist<string> ();//Generics
Lst.add ("AAA");//....
for (String str:lst) {...}
List1.addall (LIST2);//Connect List2 to List1
The array is turned into a list
List lst = arrays.aslist ("A", "B", "C");
string[] arr = new string[]{"Hell", "worl", "hah"};
List lst = arrays.aslist (arr);
Inheritance relationship of common collection classes
Collection<--list<--vector
Collection<--list<--arraylist
Collection<--list<--linkedlist
Collection<--set<--hashset
Collection<--set<--hashset<--linkedhashset
Collection<--set<--sortedset<--treeset
Map<--sortedmap<--treemap
Map<--hashmap
Queue usage
Queue<string> que = new linkedlist<string> ();
Que.offer ("Hello");//into the queue
while (que.poll () = null);//OUT queue
Que.size ();//Queue Size
Thread-Safe Queue implementation: http://blog.csdn.net/madun/article/details/20313269
Socket UDP Instance
Import java.net.*;
public class Udpsend {
public static void Main (string[] args) throws Exception {
Datagramsocket ds = new Datagramsocket ();
byte[] buf = "UDP Demo". GetBytes ();
Datagrampacket DP = new Datagrampacket (buf, Buf.length, Inetaddress.getbyname ("127.0.0.1"), 10000);
Ds.send (DP);
Ds.close ();
SYSTEM.OUT.PRINTLN ("Data send ok!");
}
}
Import java.net.*;
public class Udpreceive {
public static void Main (string[] args) throws Exception {
Datagramsocket ds = new Datagramsocket (10000);
byte[] buf = new byte[1024];
Datagrampacket dp =new datagrampacket (BUF, buf.length);
Ds.receive (DP);
String IP = dp.getaddress (). gethostaddress ();
String data = new String (Dp.getdata (), 0, Dp.getlength ());
int port = Dp.getport ();
SYSTEM.OUT.PRINTLN (Data + ":" + port + "@" + IP);
Ds.close ();
}
}
Java Learning Note (i)