1

I have two ArrayLists of the same size but one of the ArrayLists holds strings.

For example:

List 1 = new ArrayList<String>();
List 2 = new ArrayList<Integer>();

(apple , orange , pear , banana , kiwi) are in list 1 (5 , 4 , 3 , 2 , 1) are in list 2

I want it to print like this:

apple 5
orange 4
pear 3
banana 2
kiwi 1

1 Answer 1

4

Assuming they're the same size, you can iterate over them together:

for (int i = 0; i < list1.size(); ++i) {
    System.out.println(list1.get(i) + " " + list2.get(i));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.