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 6 of 6

Thread: Readable array from another method

  1. #1
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Readable array from another method

    When you've got two or potentially more methods in one class and you want to use array information from one method in the other, how can we do this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Readable array from another method

    Make the array a class variable so all methods in the class can access it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Readable array from another method

    Or a non-static field. You can learn more about Java's variables here.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Readable array from another method

    Does the term: class variable mean static? How is a variable defined at the class level vs inside a method described? I've been using the terms: class variable and method variable to mean the scope where the variable is defined.

    I guess I need to change to: instance variable and local variable.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Readable array from another method

    Does the term: class variable mean static?
    Yes.

    @maths94: My suggestion assumes (or hopes) that your designs are evolving from the beginner's stage that places almost all logic in the main() method that calls a few static methods. If you're not sure what I mean, post some code that illustrates what you're trying to do.

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Readable array from another method

    Generally non-static variables are called instance variables.
    Improving the world one idiot at a time!

Similar Threads

  1. Help with double array method
    By Dsr122076 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 21st, 2012, 04:34 PM
  2. Replies: 2
    Last Post: November 11th, 2012, 10:44 PM
  3. Accessing array of method
    By ncode in forum Java Theory & Questions
    Replies: 3
    Last Post: October 18th, 2012, 08:11 AM
  4. Contain method to read array
    By theaveguy in forum Java Theory & Questions
    Replies: 8
    Last Post: February 25th, 2012, 02:53 PM
  5. Array Search Method
    By Kyuubi426 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2011, 08:31 PM