-5

I am trying to append the data's of one or more ArrayList values into another ArrayList is it possible and may i know how ?

Example code is given below

private static final Pattern DIR_SEPORATOR = Pattern.compile("/");
    private ArrayList<File> fileList = new ArrayList<File>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String[] rootFolders = this.getStorageDirectories();

          if (rootFolders == null) {
           return;
          }
          int rl = rootFolders.length;

          File[] filelists = null;
        for (int i = 0; i < rl; i++) {
           String path = rootFolders[i];
           File target = new File(path + "/DCIM/");
           if (target.exists()) {
            filelists = target.listFiles();
               File[] filelist1  =  filelists;

           }
           File target2 = new File(path + "/DCIM/100ANDRO/");
           if (target2.exists()) {
               File[] filelist = target.listFiles();
            // Existing image to DB
            //IntialLoad(target2, Json_SupportedExtensionFromServer,CF,DP);
           }
          }

Thanks in advance.

keyser
  • 18,829
  • 16
  • 59
  • 101

3 Answers3

0

You are trying to "concatenate" two arrays (not ArrayLists). You need to use ArrayUtils.addAll() as described here:

How can I concatenate two arrays in Java?

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
0

Arraylistname.addAll(new ArraList()) try this code, I am also using this to Combine two Arraylist

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
Mohan
  • 311
  • 8
  • 15
0

You need to convert your File[] arrays to an ArrayList before adding to your ArrayList, like this:

fileList.addAll(Arrays.asList(filelist1));
samgak
  • 23,944
  • 4
  • 60
  • 82