Consider the following question which needs to be solved in Java:

You are given voterld (int), voterName (String), voterAge (int), isVoteCasted (boolean), constituency (String) respectively of 4 different voters and you are asked to find out the following:

i) Given a string parameter cons, you have to find the number of voters who belong to that particular constituency. If the number of voters belonging to that constituency is 0, then print “No votes casted”.

ii) Print the voterId of the persons whose age is less than 30 in ascending order. If there are no voters whose age is below 30, then print “No such voters.”

Sample Input:

1008

Aman

29

true

cons1

1003

Saman

43

true

cons1

1004

Kamal

28

false

cons2

1005

Ritu

48

true

cons1

cons1

Output:

3

1004

1008

Explanation:

i) The string parameter passed is cons1(last row) and there are 3 voters who belong to that constituency(voterId: 1003, 1008 & 1005). So the first output is 3.

ii) There are two voters whose age is less than 30(voterId: 1008 & 1004), so they are printed in ascending order.

I can solve it by creating a class named Voter having those 5 attributes and then creating an object array of size 4 like Voter[] v=new Voter[4]. But is there any easy way to store the data and solve it using collections like Arraylist. Suppose this program came in a competitive programming contest, what will be the shortest and easiest way to solve it?