我有一個像下面如何將字符串插入字符串數組中的特定索引並在其後移動字符串?
String singlestr="hello|world|how|are|you";
String[] arraystr = singlestr.split("|");
一個代碼和結果我有=>
arraystr[0]=hello
arraystr[1]=world
arraystr[2]=how
arraystr[3]=are
arraystr[4]=you
現在的問題是我如何可以插入一個新的字符串到3現在的位置?有什麼功能嗎?
插入一個新的字符串索引2後預期輸出:
arraystr[0]=hello
arraystr[1]=world
arraystr[2]=hi
arraystr[3]=how
arraystr[4]=are
arraystr[5]=you
陣列有侷限性喜歡你只能分配單一類型的數據,長度應該申報,你不能改變長度運行,所以最好是使用像收藏列表或數組列表此它會解決你的問題,它比這個簡單的數組有優勢 – Vickyexpert