at first i have a 2d array storing many numbers and then i used an array of hushtables to store pairs formed by the numbers of each row of the 2d array. for example in the first row of the 2d array, the numbers are 1 2 3 4 5 then the pairs should be 1,2 1,3 1,4 ,1,5 etc. the code for generating the pairs and store in hashtable is
Hashtable [] table=new Hashtable [lineCounter];
int [] pairCounter=new int[lineCounter];
for(int i=0;i<lineCounter;i++)
{
table[i]=new Hashtable();
for (int j=0;j<lineitem2[i]-1;j++)
{
for(int t=j+1;t<lineitem2[i];t++)
{
int firstnum=freItem[i][j];
int secnum=freItem[i][t];
String value=firstnum+":"+secnum;
//System.out.println(firstnum+"``"+secnum);
table[i].put(pairCounter[i],value);
pairCounter[i]++;
//System.out.println(i+":::"+table[i].get(firstnum));
}
}
}
after stored each pair of everyline, I want to compare each pair in every to the other lines to find how many times this pair shows up, the code is
Hashtable resulttable=new Hashtable();
int [] pairresult=new int [lineCounter];
for(int i=0;i<lineCounter;i++)
{
//Set set1 = table[i].entrySet();
//Iterator it1 = set1.iterator();
Enumeration keys = table[i].keys();
//for(int j=i+1;j<lineCounter;j++)
//{
while (keys.hasMoreElements())
{
int pairs=0;
//Map.Entry entry1 = (Map.Entry) it1.next();
int key = (Integer)keys.nextElement();
String curvalue = (String)table[i].get( key );
for(int j=i+1;j<lineCounter;j++)
{
//Set set2 = table[j].entrySet();
//Iterator it2 = set2.iterator();
Enumeration keys2 = table[j].keys();
while (keys2.hasMoreElements())
{
//Map.Entry entry2 = (Map.Entry) it2.next();
//System.out.println(entry2.getKey() + " and " + entry2.getValue());
int key2 = (Integer)keys2.nextElement();
String curvalue2 = (String)table[j].get( key2 );
if(curvalue.equals(curvalue2))
{
pairs++;
table[j].remove(key2);
}
}
}
if(pairs>=0.02*lineCounter)
{
resulttable.put(curvalue,pairs);
}
}
// }
}
but after ran it with the input file, I got the error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.StringBuilder.toString(StringBuilder.java:430)
is there anything wrong with my method of comparing the pairs? and why did I get that error please help thanks.