How to add new elements to an array?

后端 未结 18 1697
误落风尘
误落风尘 2020-11-22 04:55

I have the following code:

String[] where;
where.append(ContactsContract.Contacts.HAS_PHONE_NUMBER + \"=1\");
where.append(ContactsContract.Contacts.IN_VISIB         


        
18条回答
  •  不思量自难忘°
    2020-11-22 05:16

    If one really want to resize an array you could do something like this:

    String[] arr = {"a", "b", "c"};
    System.out.println(Arrays.toString(arr)); 
    // Output is: [a, b, c]
    
    arr = Arrays.copyOf(arr, 10); // new size will be 10 elements
    arr[3] = "d";
    arr[4] = "e";
    arr[5] = "f";
    
    System.out.println(Arrays.toString(arr));
    // Output is: [a, b, c, d, e, f, null, null, null, null]
    

提交回复
热议问题