×¢²á µÇ¼
±à³ÌÂÛ̳ ¡ú JAVAÂÛ̳

´´½¨·½·¨ add£¨String[] strList ,int index, String str £©{·½·¨×Ô¼ºÐ´}//ÓÃÓÚÏòstrListµÄindexλÖòåÈës

Leisurely ·¢²¼ÓÚ 2018-04-04 11:09£¬ 2793 ´Îµã»÷
javaÊý¾Ý½á¹¹£º´´½¨·½·¨ add£¨String[] strList ,int index, String str £©{·½·¨×Ô¼ºÐ´}//ÓÃÓÚÏòstrListµÄindexλÖòåÈëstr¡£
Çë¸÷λ´óÀаïæ ¶àл
10 »Ø¸´
#2
·è¿ñµÄСa2018-04-05 11:30
³ÌÐò´úÂ룺
package com.xiaoa.demo;

/*javaÊý¾Ý½á¹¹£º´´½¨·½·¨ add£¨String[] strList ,int index, String str £©{·½·¨×Ô¼ºÐ´}//ÓÃÓÚÏòstrListµÄindexλÖòåÈëstr¡£
Çë¸÷λ´óÀаïæ ¶àл
*/
public class ArrayTest {
    public static void main(String[] args) {
        String[] strList = new String[] { "Äã", "ºÃ" };
        String[] strList2 = add(strList, 2, "°¡");
        for (String string : strList2) {
            System.out.println(string);
        }
    }

    public static String[] add(String[] strList, int index, String str) {
        String[] strList2 = new String[strList.length+1];
        for(int i=0;i<strList2.length;i++) {
            if(i<index) {
                strList2[i]=strList[i];
            }
            if(i==index) {
                strList2[i] = str;
            }
            if(i>index) {
                strList2[i]=strList[i-1];
            }
        }
      

        return strList2;

    }
}
#3
ÌÒ»¨µºÖ÷ؼ2018-04-05 14:56
public class addDemo {
    public static void main(String[] args) {
        String []strList={"a","c","d"};
        int index=1;
        String str="b";
        String []newStrList=add(strList ,1,"b");
        for (String st : newStrList) {
            System.out.print(st+" ");
        }
    }

    public static String[] add(String[] strList, int index, String str) {
        ArrayList<String> arr = new ArrayList<String>();
        for (int i = 0; i <=strList.length; i++) {
            if (i<index) {
                arr.add(strList[i]);
            }else if(i==index){
                arr.add(str);
            }else {
                arr.add(strList[i-1]);
            }
        }
        String[] newstrList = arr.toArray(strList);
        return newstrList;
    }
}
#4
ÌÒ»¨µºÖ÷ؼ2018-04-05 14:57
public class addDemo {
    public static void main(String[] args) {
        String []strList={"a","c","d"};
        String []newStrList=add(strList ,1,"b");
        for (String st : newStrList) {
            System.out.print(st+" ");
        }
    }

    public static String[] add(String[] strList, int index, String str) {
        ArrayList<String> arr = new ArrayList<String>();
        for (int i = 0; i <=strList.length; i++) {
            if (i<index) {
                arr.add(strList[i]);
            }else if(i==index){
                arr.add(str);
            }else {
                arr.add(strList[i-1]);
            }
        }
        String[] newstrList = arr.toArray(strList);
        return newstrList;
    }
}
ÔÙɾһµã...
#5
ÁÖÔ¶ù2018-04-05 18:06
»Ø¸´ 4Â¥ ÌÒ»¨µºÖ÷ؼ
#6
·è¿ñµÄСa2018-04-05 19:20
»Ø¸´ 5Â¥ ÁÖÔ¶ù
ÄãÀ´¸ö¸ü¶ÌµÄßÂ
#7
ÁÖÔ¶ù2018-04-05 22:43
ÒÔÏÂÊÇÒýÓ÷è¿ñµÄСaÔÚ2018-4-5 19:20:41µÄ·¢ÑÔ£º

ÄãÀ´¸ö¸ü¶ÌµÄßÂ


°³¤Ï¤³¤ì¤òÉÏÊ֤ǤϤ¢¤ê¤Þ¤»¤ó¤è¤¦
#8
ÌÒ»¨µºÖ÷ؼ2018-04-06 23:50
»Ø¸´ 5Â¥ ÁÖÔ¶ù
°æÖ÷ºÃ.ÎÕ¸öצ~
#9
ÌÒ»¨µºÖ÷ؼ2018-04-07 00:02
ÎÒÓÖÀ´ÁË,¼¯ºÏÓÐÌí¼Ó·½·¨,ÍüÁËÓÃ,×ï¹ý...
public class Demo {
    public static void main(String[] args) {
        String []strList={"a","c","d"};
        String []newStrList=add(strList ,1,"b");
        for (String st : newStrList) {
            System.out.print(st+" ");
        }
    }

    public static String[] add(String[] strList, int index, String str) {
        ArrayList<String> arr = new ArrayList<String>();
        for (int i = 0; i < strList.length; i++) {
            arr.add(strList[i]);
        }
        arr.add(index, str);
        String[] newstrList = arr.toArray(strList);
        return newstrList;
    }
}
#10
·è¿ñµÄСa2018-04-07 09:05
»Ø¸´ 9Â¥ ÌÒ»¨µºÖ÷ؼ
À÷º¦ÁË
#11
ÌÒ»¨µºÖ÷ؼ2018-04-08 22:57
»Ø¸´ 10Â¥ ·è¿ñµÄСa
°æÖ÷¹ý½±À²,¸úÄ㻹Óв»Ð¡µÄ¾àÀë..
1