我的应用程序中有两个数组,在这种情况下我想在我的应用程序中组合两个数组但我尝试失败..这是我的代码..请结合数组数据和数据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"),
};
答案 0 :(得分:5)
首先将您的String array
转换为List
而不是使用addAll
方法添加List
示例强>
ArrayList<String> first;
ArrayList<String> second;
second.addAll(first);
答案 1 :(得分: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);
答案 2 :(得分:0)
您可以轻松使用Apache Commons Lang库 然后你的代码会看起来:
ArrayUtils.addAll(data, data2);