JavaÖм¯ºÏÈÝÆ÷ÀàListºÍSetµÄÓ÷¨
ListµÄÓ÷¨
List°üÀ¨List½Ó¿ÚÒÔ¼°List½Ó¿ÚµÄËùÓÐʵÏÖÀà¡£ÒòΪList½Ó¿ÚʵÏÖÁËCollection½Ó¿Ú£¬ËùÒÔList½Ó¿ÚÓµÓÐCollection½Ó¿ÚÌṩµÄËùÓг£Ó÷½·¨£¬ÓÖÒòΪListÊÇÁбíÀàÐÍ£¬ËùÒÔList½Ó¿Ú»¹ÌṩÁËһЩÊʺÏÓÚ×ÔÉíµÄ³£Ó÷½·¨£¬Èç±í1Ëùʾ¡£
±í1 List½Ó¿Ú¶¨ÒåµÄ³£Ó÷½·¨¼°¹¦ÄÜ
´Ó±í1¿ÉÒÔ¿´³ö£¬List½Ó¿ÚÌṩµÄÊʺÏÓÚ×ÔÉíµÄ³£Ó÷½·¨¾ùÓëË÷ÒýÓйأ¬ÕâÊÇÒòΪList¼¯ºÏΪÁбíÀàÐÍ£¬ÒÔÏßÐÔ·½Ê½´æ´¢¶ÔÏ󣬿ÉÒÔͨ¹ý¶ÔÏóµÄË÷Òý²Ù×÷¶ÔÏó¡£
List½Ó¿ÚµÄ³£ÓÃʵÏÖÀàÓÐArrayListºÍLinkedList£¬ÔÚʹÓÃList¼¯ºÏʱ£¬Í¨³£Çé¿öÏÂÉùÃ÷ΪListÀàÐÍ£¬ÊµÀý»¯Ê±¸ù¾Ýʵ¼ÊÇé¿öµÄÐèÒª£¬ÊµÀý»¯ÎªArrayList»òLinkedList£¬ÀýÈ磺
List<String> l = new ArrayList<String>();// ÀûÓÃArrayListÀàʵÀý»¯List¼¯ºÏ
List<String> l2 = new LinkedList<String>();// ÀûÓÃLinkedListÀàʵÀý»¯List¼¯ºÏ
1£®add(int index, Object obj)·½·¨ºÍset(int index, Object obj)·½·¨µÄÇø±ð
ÔÚʹÓÃList¼¯ºÏʱÐèҪעÒâÇø·Öadd(int index, Object obj)·½·¨ºÍset(int index, Object obj)·½·¨£¬Ç°ÕßÊÇÏòÖ¸¶¨Ë÷ÒýλÖÃÌí¼Ó¶ÔÏ󣬶øºóÕßÊÇÐÞ¸ÄÖ¸¶¨Ë÷ÒýλÖõĶÔÏó£¬ÀýÈçÖ´ÐÐÏÂÃæµÄ´úÂ룺
src\com\mwq\TestCollection.java¹Ø¼ü´úÂ룺
public static void main(String[] args) {
String a = "A", b = "B", c = "C", d = "D", e = "E";
List<String> list = new LinkedList<String>();
list.add(a);
list.add(e);
list.add(d);
list.set(1, b);// ½«Ë÷ÒýλÖÃΪ1µÄ¶ÔÏóeÐÞ¸ÄΪ¶ÔÏób
list.add(2, c);// ½«¶ÔÏócÌí¼Óµ½Ë÷ÒýλÖÃΪ2µÄλÖÃ
Iterator<String> it = list.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
ÔÚ¿ØÖÆ̨½«Êä³öÈçÏÂÐÅÏ¢£º
A
B
C
D
ÒòΪList¼¯ºÏ¿ÉÒÔͨ¹ýË÷ÒýλÖ÷ÃÎʶÔÏó£¬ËùÒÔ»¹¿ÉÒÔͨ¹ýforÑ»·±éÀúList¼¯ºÏ£¬ÀýÈç±éÀúÉÏÃæ´úÂëÖеÄList¼¯ºÏµÄ´úÂëÈçÏ£º
src\com\mwq\TestCollection.java¹Ø¼ü´úÂ룺
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));// ÀûÓÃget(int index)·½·¨»ñµÃÖ¸¶¨Ë÷ÒýλÖõĶÔÏó
}
src\com\mwq\TestCollection.javaÍêÕû´úÂëÈçÏ£º
package com.mwq;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.List;
public class TestCollection {
public static void main(String[] a
Ïà¹ØÎĵµ£º
0
£®ÒýÑÔ
ÔÚChinaITLAB
µ¼Ê¦ÖƸ¨µ¼ÖУ¬±ÊÕß·¢ÏÖÎʵÃ×î¶àµÄÎÊÌâĪ¹ýÓÚ"
ÈçºÎѧϰ±à³Ì£¿Java
¸ÃÈçºÎѧϰ£¿"
¡£ÀàËƵÄÎÊÌâ»Ø´ð¶àÁË£¬ÄÑÃâ»á¸Ð¾õÑá·³£¬¾ÍÃÈÉúÁËдϱ¾ÎĵÄÏë·¨¡£µ½Ê±ºòÔÙÓÐÈËÎÊÆðÀàËƵÄÎÊÌ⣬ÎÒ¿ÉÒÔ¸æËßËû£¨Ëý£©£¬ÇëÄãÈ¥¿´¿´¡¶Java
ѧϰ֮·¡·¡£°Ý¶Á¹ý̨Íå²ÌѧïÞÏÈÉúµÄ¡¶Java
ҹδÃß¡·£¬ÓÐ ......
static String string2Unicode(String s) {
try {
StringBuffer out = new StringBuffer("");
byte[] bytes = s.getBytes("unicode");
for (int i = 2; i < bytes.length - 1; i += 2) {
out.append("u");
String str = Integer.toHexString(bytes[i + 1] & 0xff);
f ......
µ±JVM£¨JavaÐéÄâ»ú£©Æô¶¯Ê±£¬»áÐγÉÓÉÈý¸öÀà¼ÓÔØÆ÷×é³ÉµÄ³õʼÀà¼ÓÔØÆ÷²ã´Î½á¹¹£º
bootstrap classloader
|
extension classloader
&n ......
ʹÓÃJava²Ù×÷Îı¾ÎļþµÄ·½·¨Ïê½â
ÕªÒª: ×î³õjavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀà
×î³õjavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀ࣬ÕâÁ½¸öÀ඼ÊdzéÏ ......