java³£Óü¯ºÏÀàÏê½â
java³£Óü¯ºÏÀàÏê½â£¨ÓÐÀý×Ó£¬¾µäÄÅ£¡£¡£¡¼¯ºÏÀàºýÍ¿µÄÀ´¿´°¡£¡£¡£©
Collections Framework
¼¯ºÏ¿ò¼ÜÊÇÒ»¸öͳһµÄ¼Ü¹¹,ÓÃÀ´±íʾºÍ²Ù×÷¼¯ºÏ.
¼¯ºÏ¿ò¼ÜÖ÷ÒªÊÇÓɽӿÚ,³éÏóÀàºÍʵÏÖÀ๹³É.
½Ó¿Ú:À¶É«£»ÊµÏÖÀࣺºìÉ«
Collection
|_____Set(HashSet)
| |_____SortedSet(TreeSet)
|_____List(LinkedList,ArrayList)
Collection:¼¯ºÏ²ã´ÎÖеĸù½Ó¿Ú£¬JDKûÓÐÌṩÕâ¸ö½Ó¿ÚµÄʵÏÖÀà¡£
Set:²»ÄÜ°üº¬Öظ´µÄÔªËØ£¬×Ó½Ó¿ÚSortedSetÊÇÒ»¸ö°´ÕÕÉýÐòÅÅÁеÄÔªËصÄSet¡£
List:¿ÉÒÔ°üº¬Öظ´µÄÔªËØ£¬ÊÇÒ»¸öÓÐÐòµÄ¼¯ºÏ£¬ÌṩÁË°´Ë÷Òý·ÃÎʵķ½Ê½£¬ÓдÎÐò£¬Î»Öò»¸Ä±ä¡£
Collection½Ó¿Ú³£Óõķ½·¨£º
boolean
add(E o)
È·±£´Ë collection °üº¬Ö¸¶¨µÄÔªËØ£¨¿ÉÑ¡²Ù×÷£©¡£
boolean
contains(Object o)
Èç¹û´Ë collection °üº¬Ö¸¶¨µÄÔªËØ£¬Ôò·µ»Ø true¡£
boolean
remove(Object o)
´Ó´Ë collection ÖÐÒƳýÖ¸¶¨ÔªËصĵ¥¸öʵÀý£¬Èç¹û´æÔڵĻ°£¨¿ÉÑ¡²Ù×÷£©¡£
int
size()
·µ»Ø´Ë collection ÖеÄÔªËØÊý¡£
Object[]
toArray()
·µ»Ø°üº¬´Ë collection ÖÐËùÓÐÔªËصÄÊý×é¡£
Iterator<E>
iterator()
·µ»ØÔÚ´Ë collection µÄÔªËØÉϽøÐеü´úµÄµü´úÆ÷¡£
List½Ó¿ÚÌØÓз½·¨£º
E
get(int index)
·µ»ØÁбíÖÐÖ¸¶¨Î»ÖõÄÔªËØ¡£
SortedSet½Ó¿ÚÌØÓз½·¨£º
E
first()
·µ»Ø´ËÓÐÐò¼¯ºÏÖе±Ç°µÚÒ»¸ö£¨×îСµÄ£©ÔªËØ¡£
E
last()
·µ»Ø´ËÓÐÐò¼¯ºÏÖÐ×îºóÒ»¸ö£¨×î´óµÄ£©ÔªËØ¡£
¼¯ºÏ¿ò¼ÜÖеÄʵÏÖÀà.
ArrayList:
±¾ÖÊ£ºÎÒÃÇ¿ÉÒÔ½«Æä¿´×÷ÊÇÄܹ»×Ô¶¯Ôö³¤ÈÝÁ¿µÄÊý×飬ʵ¼ÊÊDzÉÓöÔÏóÊý×éʵÏֵġ£
×Ô¶¯Ôö³¤ÈÝÁ¿
Ïà¹ØÎĵµ£º
Java IOµÄÒ»°ãʹÓÃÔÔò£º
Ò»¡¢°´Êý¾ÝÀ´Ô´£¨È¥Ïò£©·ÖÀࣺ
1¡¢ÊÇÎļþ£º FileInputStream, FileOutputStream, FileReader, FileWriter
2¡¢ÊÇbyte[]£ºByteArrayInputStream, ByteArrayOutputStream
3¡¢ÊÇChar[]: CharArrayReader, CharArrayWriter
4¡¢ÊÇString: StringBufferInputStream, StringReader, StringWriter
5¡¢ ......
½ñÌìÓöµ½ÕâÑùµÄÎÊÌâ¡£ÐèÒªÏÂÔØÒ»¸öÎļþ£¬¸ÃÎļþµÄurlÈçÏ£º hxxp://www.abc.com/view/img/%E7%BD%91%E4%B8%8A%E8%B4%AD%E7%89%A9.rar
´ËÁ´½ÓÔÚä¯ÀÀÆ÷Ï»áÖض¨Ïòµ½±ðµÄÍøÕ¾¡£ËùÒÔÏÂÔØÏÂÀ´µÄÎļþ²¢·ÇÎÒÏëÒªµÄ¡£²éÁËÏÂÔÀ´ÊÇurl±àÂëºóµÄÎļþÃû¡£ÄÇôҪÏëÏÂÔؾͱØÐë¶ÔÕâ¸ö±àÂë½øÐнâÂë¡£¡£¡£¡£¡£
& ......
Ç°²»¾ÃдÁ˸öÏÂÔØÎļþµÄ·½·¨¡£¾¹ýÒ»¶Îʱ¼äÔÚ³ÌÐòÖеÄÔËÓ㬷¢ÏÖÁ˼¸¸öÎÊÌâ¡£ÐÞÕýһϣº
public static File saveToFiles(String destUrl,String path) throws IOException {
final int BUFFER_SIZE = 4096;
&nb ......
import java.io.*;
//¶àÏ̱߳à³Ì
public class MultiThread
{
public static void main(String args[])
{
System.out.println("ÎÒÊÇÖ÷Ïß³Ì!");
//ÏÂÃæ´´½¨Ïß³ÌʵÀýthread1
ThreadUseExtends thread1=new ThreadUseExtends();
//´´½¨thread2ʱÒÔʵÏÖÁ ......
public class TextDemo {
public static void main(String[] args) {
RunnableEemo r1 = new RunnableEemo();
r1.REemo(r1);
System.out.println(r1.print());
}
}
class RunnableEemo extends ThreadRun implements Runnable {
Thread t2 = null;
public void REemo(RunnableEemo r1) {
Thread t1 = ......