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: Please help with passing an array to a new class

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help with passing an array to a new class

    I have no knowledge of passing to and from a class to another class so if anyone can please help me.

    I have to enter integers in a Java class with a GUI and then sort the integers in a different class in the same package. So far I have been able to sort it in the same class but need to only sort it in a different class and then pass the sorted array back to be displayed in the main class.
    Please help
    This is my working code so far:

    int k;

    int array1[]=new int[3];
    array1[0] = Integer.parseInt(jTextField1.getText());
    array1[1] = Integer.parseInt(jTextField2.getText());
    array1[2] = Integer.parseInt(jTextField3.getText());

    Arrays.sort(array1);


    for (k=0;k<4;k++)
    {
    jTextArea1.append(Integer.toString(array1[k]));
    jTextArea1.append(" \n");
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Please help with passing an array to a new class

    Create a different class, create a method that sorts the array, then pass the array to said class.

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/61217-sort-array-different-class.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. passing refeerence of class
    By jack_nutt in forum Object Oriented Programming
    Replies: 2
    Last Post: September 30th, 2011, 02:14 PM
  2. HELP. Passing Array to class.
    By videodrome in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 13th, 2010, 04:35 AM
  3. Passing a value to another class
    By Semple in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2010, 05:49 PM
  4. [SOLVED] Class not passing information
    By DiPep in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 26th, 2010, 10:04 AM
  5. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM