Reputation: 718
I am having a little bit of trouble figuring out some complicated logic required for a program at work.
This program is designed to compare "transactions" between two folders. Each folder can contain any number of files and each file (XML Document) can contain any number of transactions. Each transaction will have 5 tags.
I must compare two folders and see if any transactions match.
To do this, I am using a HashMap
and putting a String[][]
array inside of it. Each key in the HashMap
will represent 1 file. The row in the String will represent a transaction and the columns will represent the tags.
I'm having trouble figuring out how to access the String[][]
from within the HashMap
. I need to get the number of transactions (rows).
Here is how I do the above:
// Creating the HashMap and Array[][]
public static Map<Integer, String[][]> Pain008TransactionsCollection = new HashMap();
public static String[][] Pain008Transactions;
//Here is the logic where I populate the HashMap.
int transactionSize = EndToEndId.size();
//Creates a 2D array with one dimension for each transaction and six dimensions
//for relevant tags + filename.
Pain008Transactions = new String[transactionSize][6];
//For each transaction..
for(int i = 0; i < transactionSize; i++){
//Below will add each value into the 2D array for each transaction. Note that the
//filename is also added so that it can be easily associated with a transaction later.
Pain008Transactions[i][0]=EndToEndId.get(i);
Pain008Transactions[i][1]=InstdAmt.get(i);
Pain008Transactions[i][2]=MmbId.get(i);
Pain008Transactions[i][3]=DbtrNm.get(i);
Pain008Transactions[i][4]=OthrId.get(i);
Pain008Transactions[i][5]=GetFiles.pain008Files.get(currentFile).toString();
}
//Puts the 2D array into the collections map at the position of the current
//file in sequence.
Pain008TransactionsCollection.put(currentFile, Pain008Transactions);
System.out.println(Pain008TransactionsCollection);
I know that to get the total number of HashMap
key's I use this:
Pain008TransactionsCollection.size()
and I know to get the rows for the String[][] I use
Pain008Transactions.length()
But I am not sure how to call the HashMap
key and then get the row length for that particular key.
Any help would be really appreciated.
Upvotes: 1
Views: 279
Reputation: 140447
You iterate the map, like
for (Entry<Integer, String[][]> entry : Pain008TransactionsCollection.entrySet() ) {
Integer key = entry.getKey();
String[][] data = entry.getValue();
}
Thats it. Or do I miss something?
You retrieve a single value and its dimensions with:
String data[][] data = Pain008TransactionsCollection.get(0);
int rowCount = data.length;
int columnCount = data[0].length;
for example.
Upvotes: 1