-1

I have two array in my applications, in this case i want to combine two array in my application but i tried and failed.. here is my code.. please combine array data and 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"),
};
rciovati
  • 27,603
  • 6
  • 82
  • 101
Jamaludin Iqba
  • 191
  • 1
  • 2
  • 9

3 Answers3

5

First convert your String array to List than use addAll metod to add List

Example

ArrayList<String> first;
ArrayList<String> second;
second.addAll(first);
Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
3

Here you go.

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);
unzoomed
  • 580
  • 1
  • 6
  • 23
0

You can easly use Apache Commons Lang library.
Then your code will look:

ArrayUtils.addAll(data, data2);

Here is documetation for this method:
http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/ArrayUtils.html#addAll(java.lang.Object[], java.lang.Object[])

Maniek
  • 67
  • 5