Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do you pass an Array as a Parameter?

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default How do you pass an Array as a Parameter?

    Hi, right now I'm writing a code that needs to pass an Array "numbers" that contains a text file from my driver into my constructor. For example, for primitives it is easy:

    public Stats (int a)

    or even ArrayLists:

    public Stats (ArrayList<Integer> a)

    How would you pass an Array this way? Thank you.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How do you pass an Array as a Parameter?

    Passing anything works exactly the same regardless of the data type. The only time you'll run into a difference is between primitives and objects (primitives pass by value and objects pass by reference). I believe arrays are actually objects, so they will be passed by reference too (even if they are arrays of primitives).

    public Stats(int[] a)

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Arius (January 23rd, 2010)

Similar Threads

  1. Object array to int array?
    By rsala004 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2009, 04:09 AM
  2. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 04:31 AM
  3. Storing an array into an array
    By vluong in forum Collections and Generics
    Replies: 4
    Last Post: September 22nd, 2009, 02:14 PM
  4. How to Pass unlimited Arguments to a Function
    By neo_2010 in forum Java Programming Tutorials
    Replies: 2
    Last Post: July 8th, 2009, 11:39 AM