Current Position:Home > How to extend an array?

How to extend an array?

Update:11-30Source: network consolidation
Advertisement
Hi,
how to extend an array
int[] b = new int[] {1, 2, 3};by adding 4, 5, 6 without copying?
thanks a lot
aldo

The Best Answer

Advertisement
You can't
     int [] b = {1,2,3};
     int [] a = {4,5,6};
     int [] tmp = new int [b.length + a.length];
     System.arraycopy(b, 0, tmp, 0, b.length);
     System.arraycopy(a, 0, tmp, b.length ,a.length);
     b = tmp;
     System.out.println(Arrays.toString(b));
  • How to extend an array? Update:11-30

    Hi, how to extend an array int[] b = new int[] {1, 2, 3};by adding 4, 5, 6 without copying? thanks a lot aldoYou can't      int [] b = {1,2,3};      int [] a = {4,5,6};      int [] tmp = new int [b.length + a.length];      System.arraycopy(b, 0, tmp,

  • Extending an array multiple times - Help! Update:11-30

    Hi everyone, I am very new to Java (doing my first class now) and I need some help with making an array larger. I have written a program that will display a list of products created in a static array. The program needs to include an "add" button

  • Extending an Array Update:10-11

    I have created a class of objects, with fields, constructors, methods, etc. So far, so good. Now I would like to create an array of these objects, and I have some methods that I would like to create that would manipulate the objects in an array. Is i

  • How to Extend an Array of an Array of an Object Update:11-30

    Hi! I'm created these types in my DB: TYPE SONO_ROW AS OBJECT (DATO NUMBER, FECHA DATE); TYPE SONO_TABLE IS VARRAY(1000) OF SONO_ROW; TYPE SONO_ARRAY IS VARRAY(1000) OF SONO_TABLE; Well, I have a problem when I trying to load SONO_ARRAY, because I ca

  • Extend a Array of a Array of a Object Update:11-30

    Hi! I'm created these types in my DB: TYPE SONO_ROW AS OBJECT (DATO NUMBER, FECHA DATE); TYPE SONO_TABLE IS VARRAY(1000) OF SONO_ROW; TYPE SONO_ARRAY IS VARRAY(1000) OF SONO_TABLE; Well, I have a problem when I trying to load SONO_ARRAY, because I ca

  • Possible bug: Saving array with extended and double precision to spreadshee​t Update:10-11

    If one concatenates a double precision array and an extended precision array with the "build array" vi and then saves using "Write to Spreadsheet File" vi any digits to the right of the decimal place are set to zero in the saved file.

  • Public class ArrayEx extends Array Update:11-30

    Hi, I'm very bad at OO programming, but I'm trying to learn. I want to add some functions to my Arrays, like checking if arrays contain a value (indexOf can be equal to 0, which is false, though actually I'm used to the loose data typing of as2, so t

  • Extending Array class, get Error #1069: Property 0 not found with indexOf call Update:11-30

    I'm using inheritance to extend the Array class to create a Paths class that moves Sprites/MovieClips around on the screen. I'm getting an odd error on a call to indexOf. Here's the error: ReferenceError: Error #1069: Property 0 not found on Paths an

  • Array of file variables Update:10-11

    I wanted to have an array of variables of type Text_IO.File_Type. So I declared: TYPE file_array IS VARRAY(20) of Text_IO.File_Type; f_array file_array; begin      f_array(1) := Text_IO.Fopen('c:\file', 'w'); This compiled but didn't work, the Fopen

  • Using an array of primitive Update:11-30

    How can I truncate an array of (primitive) double? Is it like the following, or some more obviously legitimate way? double[] dArr=new double[12345678]; dArr = Arrays.copyOf(dArr,7234567); I don't want to have both sizes allocated at the same time. Al