How to combine 2 int Array into ONE int Array ?

Discussion in 'Java' started by S300, Aug 19, 2003.

  1. S300

    S300 Guest

    How to combine 2 int Array into ONE int Array ?


    thanks
    S300, Aug 19, 2003
    #1
    1. Advertising

  2. S300

    Dario Guest

    S300 wrote:

    > How to combine 2 int Array into ONE int Array ?


    class A49 {
    public static int[] getONE(int[] arg1, int[] arg2) {
    int[] result = new int[arg1.length+arg2.length];
    System.arraycopy(arg1, 0, result, 0, arg1.length);
    System.arraycopy(arg2, 0, result, arg1.length, arg2.length);
    return result;
    }
    }
    Dario, Aug 19, 2003
    #2
    1. Advertising

  3. S300

    Roedy Green Guest

    On Tue, 19 Aug 2003 12:03:45 +0800, "S300" <> wrote or
    quoted :

    >How to combine 2 int Array into ONE int Array ?


    allocate a new array and use a couple of for loops or a couple of
    arraycopys.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 19, 2003
    #3
  4. S300

    Tim Tyler Guest

    biro <> wrote:

    : int[] newarray = new int[array1.length + array2.length];

    : And then use System.arraycopy to populate it.

    : Why it's in System and not Arrays I don't know.

    "Arrays" didn't exist at the time. That's why.
    --
    __________
    |im |yler http://timtyler.org/
    Tim Tyler, Aug 19, 2003
    #4
  5. S300

    Roedy Green Guest

    On Tue, 19 Aug 2003 12:06:03 +0100, "biro" <> wrote or
    quoted :

    >
    >Why it's in System and not Arrays I don't know.



    historical. Arrays was not invented until around Java 1.2
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 19, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ad
    Replies:
    1
    Views:
    371
    =?Utf-8?B?dmVlcmEgc2VraGFyIGtvdGE=?=
    Jul 14, 2005
  2. David Lozzi

    Combine 2 or more XMLDocuments into one...

    David Lozzi, Oct 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    570
    Steven Cheng[MSFT]
    Oct 19, 2005
  3. David Lozzi

    Combine Crystal Reports into one PDF

    David Lozzi, Apr 17, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    698
    David Lozzi
    Apr 17, 2006
  4. John Dalberg
    Replies:
    2
    Views:
    11,683
    Spartanicus
    Aug 20, 2006
  5. fancyerii
    Replies:
    21
    Views:
    1,488
    Roedy Green
    Nov 5, 2007
Loading...

Share This Page