ArrayList using a Generic Type Issue

I am having issues with capturing necessary data that has been placed into an ArrayList using Generics. This should be a very simple task but apparently the process is not behaving properly. I am using the JDeveloper IDE ver (11.1.7.0) So onward to the demonstration of the problem.

I have a class called:
class InstitutionAidValue -[Class is comprised with setter and getter methods]
    private BigDecimal amount;
    private Boolean countIndividual;
    private Boolean countSport;
    private int sourceCode;

I have another class that processes a range of information and then sends all of the elements that were set in InstitutionAidValue over to another class to perform the delivery of the data elements:
class Student-[This class will gather all of the data from the fields in InstitutionAidValue and store into another Array of type InstitutionAidValue]

  //Create array list of data for financial aid value
  List<InstitutionAidValue> instituteList = new ArrayList<InstitutionAidValue>();

Begin the process of populating my ArrayList with values from InstitutionAidValue
                        if (rset.getInt("ATROOM_CODE") != 0) {
                            institutionAid.setSourceCode(rset.getInt("ATROOM_CODE"));
                            System.out.println("ATROOM CODE THAT IS SET" + ' ' + institutionAid.getSourceCode());
                            institutionAid.setAmount(rset.getBigDecimal("ATROOM_AMT"));
                            System.out.println("ATROOM AMT THAT IS SET" + ' ' + institutionAid.getAmount());
                            institutionAid.setCountIndividual(rset.getBoolean("COUNT_INDIVIDUAL"));
                            institutionAid.setCountSport(rset.getBoolean("COUNT_SPORT"));

instituteList.add(institutionAid);
}

--I begin to look to determine the size of the ArrayList once it has been populated with the supposed values
                        if (instituteList.size() > 0 ) {
                            System.out.println("Institute List has values");
                        }
  --Problem
The message in this case does not even display, so I would imagine that the elements did not populate into the ArrayList even though that I know they exist. I have used getter methods to display in my log file. HELP!!!
SeaghostAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
how about using a debugger? thins like this can be solved easily with a debugger.
0
dpearsonCommented:
As you say, instituteList must be empty.

Given your code has this test:
 if (rset.getInt("ATROOM_CODE") != 0) {
     ...
     instituteList.add(institutionAid);
 }

the implication is that either
     a) rset.getInt("ATROOM_CODE") is always 0
or b) you're not calling that code at all

I'd make sure that if statement is being executed (add a System.printout before it) and then I'd post the code for getInt() and maybe we can help.

Doug

P.S. If you're comparing Strings inside the getInt() method, make sure you are using the "equals" method, so:
string1.equals(string2) ;   // This works
not
string1 == string2 ; // This doesn't work
1
SeaghostAuthor Commented:
Ok, I have already setup my System.out.println message throughout the code and I do see that the values are in my ArrayList. However; when I go through my ArrayList with the simple FOR LOOP, it appears that the values that are set, are exactly the same. If I am accepting an OBJECT Type into my array, wouldn't the Array List have different values if I am adding the values through my If Statements?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

SeaghostAuthor Commented:
P.S. - What I mean from my above post is if I have an object that has 4 fields, when I add that object to my ArrayList, I should be able to see the different values for that object that I have added correct?
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I can't be 100% sure from the small amount of code that you have posted but I think the problem is that you are inserting the same object into your list but changing the values each time around. So, at some point you must have a line of code something like this...

InstitutionAidValue institutionAid = new InstitutionAidValue();

But my guess is that that line is OUTSIDE your loop that processes each row of the resultset. You need to move that line to be INSIDE the loop (by the looks of your code it could go between the IF statement and the call to .setSourceCode)

Basically that line of code creates a new object and so it has to be inside the loop so a new object can be created each time around the loop otherwise there is only ONE object that just gets it's values changed each time around the loop, irrespective of the fact that you are adding it to the list each time. An object can still change, even when it has already been added to the list.

Now this doesn't solve the initial question of why you didn't even get the message printed for having .size() > 0 but can I assume that you solved that issue since your last posts indicate that your list is now populated?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SeaghostAuthor Commented:
This was exactly the cause of my issue and your explanation was on point. Thank You So Much
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome, glad to help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.