-1

我的应用程序中有两个数组,在这种情况下,我想在我的应用程序中组合两个数组,但我尝试过但失败了..这是我的代码..请结合数组数据和 data2:

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"),
};
4

3 回答 3

5

首先将您的转换String array为而List不是使用addAll方法添加List

例子

ArrayList<String> first;
ArrayList<String> second;
second.addAll(first);
于 2013-04-26T07:59:42.663 回答
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);
于 2013-04-26T08:12:52.083 回答
0

您可以轻松使用 Apache Commons Lang 库。
然后您的代码将如下所示:

ArrayUtils.addAll(data, data2);

这是此方法的文档:http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/ArrayUtils.html#addAll
(java.lang.Object[] , java.lang.Object[])

于 2013-04-26T08:35:39.380 回答