Question: In Java Hello, I am trying to find a way to use a for loop to increment the values of a hashmap(t) , with two
In Java
Hello, I am trying to find a way to use a for loop to increment the values of a hashmap(t) , with two values (id, testCaseId). Right now I am having trouble trying to increment the hashmap in the for loop. Was wondering if anyone could help me out on this. The results should print out three hashmaps in an arraylist. The first one passing (1) and the others failing (5) in the status. The list remains 7 and the id increments 56,57,58)
package loops;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class loops {
public static final int PASSED = 1;
public static final int FAILED = 5;
static ArrayList> Results = new ArrayList>();
public static void main(String[] args) {
if (1 ==1 ) {
addResultForTestCase(1, PASSED, Results);
} else
{
addResultForTestCase(1,FAILED,Results);}
if (1 ==2 ) {
addResultForTestCase(2, PASSED, Results);
} else
{
addResultForTestCase(2,FAILED,Results);}
if (1 ==3 ) {
addResultForTestCase(2, PASSED, Results);
} else
{
addResultForTestCase(2,FAILED,Results);}
}
//Adds results in hashmap
public static void addResultForTestCase(int testCaseId, int status, ArrayList> newResults
) {
int count = 1;
int Id = 56;
int t = 1;
for (Map m : newResults) {
try {
if(testCaseId == count) {
Map test,t= new HashMap(){{put("list", 7); put("id", Id ); put("status", status);}};
newResults.add(test,1);
count++ ;Id++; t++;
}
} catch (IllegalArgumentException | SecurityException e) {
e.printStackTrace();
}
}
System.out.println(newResults);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
