2013-04-26 108 views
-1

我在我的應用程序中有兩個數組,在這種情況下,我想在我的應用程序中組合兩個數組,但我嘗試並失敗..這是我的代碼..請組合陣列數據和數據2:如何組合兩個陣列

Data[] data = { 
     new Data(-79.400917f,43.661049f, "New New College Res", 
       "Residence building (new concrete high-rise)", "R.drawable.mr_kun"), 
     new Data(-79.394524f,43.655796f, "Baldwin Street", 
       "Here be many good restaurants!", "R.drawable.mr_kun"), 
     new Data(-79.402206f,43.657688f, "College St", 
       "Lots of discount computer stores if you forgot a cable or need to buy hardware.", "R.drawable.mr_kun"),  
     new Data(-79.390381f,43.659878f, "Queens Park Subway", 
       "Quickest way to the north-south (Yonge-University-Spadina) subway/metro line", "R.drawable.mr_kun"), 

}; 

Data[] data2 = { 
     new Data(-79.403732f,43.666801f, "Spadina Subway", 
       "Quickest way to the east-west (Bloor-Danforth) subway/metro line", "R.drawable.mr_kun"), 
     new Data(-79.399696f,43.667873f, "St George Subway back door", 
       "Token-only admittance, else use Spadina or Bedford entrances!", "R.drawable.mr_kun"), 
     new Data(-79.384163f,43.655083f, "Eaton Centre (megamall)", 
       "One of the largest indoor shopping centres in eastern Canada. Runs from Dundas to Queen.", "R.drawable.mr_kun"), 
}; 

回答

3

你在這裏。

Data[] mergedArray = new Data[data.length + data2.length]; 
System.arraycopy(data, 0, mergedArray, 0, data.length); 
System.arraycopy(data2, 0, mergedArray, data.length, data2.length); 
+0

+1好的發現...這似乎是工作.. – 2013-04-26 08:20:58

+0

我不問這個問題......我相信,如果OP發現這個答案爲他工作,他會接受你的答案.. :) – 2013-04-26 08:23:29

+0

Iam對不起但不工作.. – 2013-04-26 14:43:54

5

首先轉換您String arrayList不是使用addAll梅託德添加List

ArrayList<String> first; 
ArrayList<String> second; 
second.addAll(first); 
+0

我都試過,但錯誤..我喜歡的類型數組數據不串..請給我幫助.. – 2013-04-26 08:06:08

+1

這就是爲什麼他寫了「FIRST轉換字符串數組到列表:-) – bofredo 2013-04-26 08:08:46

+0

給我任何其他的解決方案..? – 2013-04-26 08:09:56