We help IT Professionals succeed at work.

How do I work with an multidimensional ArrayList of Strings and Integers?

Eindoofus
Eindoofus asked
on
Medium Priority
316 Views
Last Modified: 2012-06-22
I need to create an ArrayList with two columns, one being a String and the second an Integer. Here is an example:

BLUE - null?
Ships - 3
Ports - 4

And I also need to know how to access one of the column and rows to add a value to it. For example if the "Ports" decrease to three, how would I go about changing this in the ArrayList?

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
You should use an ArrayList<SomeBean> where SomeBean encapsulates a String attribute and an Integer one

Author

Commented:
Thanks, but could you please be more specific. I still don't no what code to use to do this.
CERTIFIED EXPERT
Top Expert 2016
Commented:
Something like
public class Info {
    private String name;
    private Integer count;

    public Info(){}

    public Info(String name, String count) {
	this.name = name;
	this.count = count;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getCount() {
        return this.count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }
}

=================


List<Info> infoList = new ArrayList<Info>();
infoList.add(new Info("Ships", 3));

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
:)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.