I am trying to populate an ArrayList with objects to go to the ArrayAdapter (in the end). I lost some code in a small test project to illustrate the problem.
I have a class called "Rules" in which there are two members: "Gender and Age" (Rules.Java). In the MyArrayTest class, I instantiate the Rules objects and add them to the array_parts ArrayList. When I loop over the array, the loop executes the expected number of times, but duplicates the last element. Please can someone please indicate why.
Rules.Java
public class Rules { public static String Gender; public static Integer Age; public Rules(String G, Integer C) {
Main class - MyArrayTest.java
import java.util.ArrayList; public class MyArrayTest { private static ArrayList<Rules> rule_parts = new ArrayList<Rules>(); public static void main(String[] args) {
The output is as follows:
Rules:
Female 22
Female 22
source share