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

Thread: How to access an ArrayList of another class?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to access an ArrayList of another class?

    public class MemberAccoutList{

    private ArrayList<MemberAccount> membrAcc = new ArrayList<MemberAccount>();

    public ArrayList<MemberAccount> getMembrAcc()
    {
    return membrAcc;
    }
    }

    public class MemeberAccount{

    private int mobileNumber;
    private String password;




    //Create a MemberAccount constructor
    public MemberAccount(int mobNum, String pswd)
    {
    this.mobileNumber = mobNum;
    this.password = pswd;


    }

    public void setMobileNumber(int mobileNumber)
    {
    this.mobileNumber = mobileNumber;
    }


    public int getMobileNumber()
    {
    return mobileNumber;
    }

    }

    public class Validation{

    public boolean joinValidation(String num,String pass, String pass2){

    int number = Integer.parseInt(num);

    for(MemberAccount memb : ma.getMembrAcc())// why this isn't working??? it gives me null
    {

    if(memb.getMobileNumber() == number)
    {
    JOptionPane.showMessageDialog(null, "The mobile number already exist","Error",JOptionPane.ERROR_MESSAGE);
    return false;

    }

    }

    }
    }

    }


  2. #2
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    383
    My Mood
    Angry
    Thanks
    46
    Thanked 63 Times in 63 Posts

    Default Re: How to access an ArrayList of another class?

    I should point out that ArrayList has a get(int index) method that returns the item at that index. You don't really need to use an iterator with the ArrayList class.
    JavaScript is NOT Java.

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

    mflevie44 (October 22nd, 2013)

  4. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to access an ArrayList of another class?

    Sorry!!! it doesn't have one I just update it.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: How to access an ArrayList of another class?

    Please read the Announcement topic at the top of the sub-forum for new user tips, including how to post your code in code tags. Update your post again to include the code tags.

Similar Threads

  1. How to access derived class field values?
    By ehsansh in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 1st, 2013, 06:08 AM
  2. Cannot access class attributes
    By Cyburg in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 29th, 2010, 08:30 AM
  3. How do i access methods from an arraylist?
    By kiph in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 7th, 2010, 08:52 AM
  4. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 06:20 PM
  5. How can i store ArrayList objects in Access database
    By frankycool in forum JDBC & Databases
    Replies: 0
    Last Post: November 4th, 2009, 12:44 AM

Tags for this Thread