M
mikew01
Hello, I need to compare 2 lists of byte arrays.
I wanted to use something like Collections.sort then compare each
array in the order they came out of the List but this will not work
because a byte array object does not implement Comparable, so I'm
doing this at present...
<code>
protected void compareDBVsIProds( List convertedProds, List
iProducts )
{
int matches = iProducts.size();
for( int i = 0; i < iProducts.size(); i++ )
{
byte[] iArr = ( byte[] ) iProducts.get( ( i ) );
for( int j = 0; j < convertedProds.size(); j++ )
{
byte[] prodArr = ( byte[] )convertedProds.get( j );
if( Arrays.equals( iArr, prodArr ) )
{
matches--;
break;
}
}
}
if( matches != 0 )
{
String error = matches + " products have not been matched";
throw new RuntimeException( error );
}
}
</code>
Could anyone suggest a neater way of achieving this task?
TIA
Mike.
I wanted to use something like Collections.sort then compare each
array in the order they came out of the List but this will not work
because a byte array object does not implement Comparable, so I'm
doing this at present...
<code>
protected void compareDBVsIProds( List convertedProds, List
iProducts )
{
int matches = iProducts.size();
for( int i = 0; i < iProducts.size(); i++ )
{
byte[] iArr = ( byte[] ) iProducts.get( ( i ) );
for( int j = 0; j < convertedProds.size(); j++ )
{
byte[] prodArr = ( byte[] )convertedProds.get( j );
if( Arrays.equals( iArr, prodArr ) )
{
matches--;
break;
}
}
}
if( matches != 0 )
{
String error = matches + " products have not been matched";
throw new RuntimeException( error );
}
}
</code>
Could anyone suggest a neater way of achieving this task?
TIA
Mike.