在我的应用程序中,我有2个图像具有相同的尺寸,我会给他们的RGB数据并进行比较。在j2me中,我们不能使用java.util.Arrays等Arrays.equals(array1, array2)
方法。比较它们的一种方法是使用为循环并比较两个int数组中的每个元素,但是我正在寻找更好的方法。当我在web中搜索时,发现有一些equals()方法的ArrayUtils类here,但它是比较两个对象数组的方法,并且在比较int数组之前,它将它们转换为ArrayToEnumeration(Object数组)的枚举,该枚举根据给定对象创建枚举。
最后这是我的问题:
有没有更好的方法来比较j2me中的两个int数组?比较j2me中的两个int数组?
1
A
回答
0
尝试这样的事情。从的Util类
public static boolean equals(byte[] a, byte[] a2) {
if (a==a2)
return true;
if (a==null || a2==null)
return false;
int length = a.length;
if (a2.length != length)
return false;
for (int i=0; i<length; i++)
if (a[i] != a2[i])
return false;
return true;
}
0
private int compareArray(String[] _array1, String[] _array2){
Vector m_length1 = new Vector();
Vector m_length2 = new Vector();
if(_array1 && _array2!=null)
{
for(int i=0; i<_array1.length; i++){
if(m_length1[i]!=null){
m_length1.add(_array1[i]);
}
}
for(int j=0; j<_array2.length; j++){
if(m_length2[j]!=null){
m_length2.add(_array2[j]);
}
}
}
if(m_length1.size()==m_length2.size()){
return 0; /*matching*/
}else{
return -1; /*no matching*/
}
}
你可以修改它作为int数组或者你可以比较每个值的字节。例如, ;
byte sample[] = {0,0,0,0};
sample= yourValue.getBytes();
+0
:谢谢你的时间,我做到了,但正如我在问题中注意到的,我试图找到比“for”更好的方法。 – hasanghaforian 2012-03-01 11:43:49
+0
而不是for,你可以使用迭代器来检查两个向量。 – 2012-03-01 11:49:23
0
转换字节数组字符串:
public boolean equals(byte[] b1, byte[] b2){
String strB1 = new String(b1);
String strB2 = new String(b2);
if(strB1.equals(strB2)){
return true;
}
else{
return false;
}
}
相关问题
- 1. 如何比较int中的int数组
- 2. 比较两个数组中的比特
- 3. 比较tsql中的两个int值
- 4. angularjs比较两个数组
- 5. PHP比较两个数组?
- 6. 比较两个数组?
- 7. 比较两个数组
- 8. PHP - 比较两个数组
- 9. 比较两个数组
- 10. 比较2 int数组
- 11. 比较两个数组中的元素
- 12. 比较as3中的两个数组
- 13. C# - 比较两个数组中的值
- 14. 在Ruby中比较两个数组
- 15. Java:如何为非重复元素比较两个int []数组?
- 16. Postgres的 - 比较两个数组
- 17. 比较两个数组的值
- 18. 比较两个数组的值
- 19. 比较两个数组的ActionScript 3
- 20. 比较的两个数组PHP元素
- 21. 如何比较两个数组的值?
- 22. Python:比较两个数组的元素
- 23. 的Javascript比较单个int到int数组
- 24. 比较比较Int
- 25. 如何比较两个数组中的两个字段 - Perl
- 26. 比较两个数组是否有在两个数组
- 27. 我如何比较两个数组php
- 28. 比较两个数组和PHP
- 29. 如何比较两个数组对象
- 30. 试图比较两个数组PHP
:谢谢您的时间,我做到了,但正如我在这个问题通知我试图找到比“为”更好的办法。 – hasanghaforian 2012-03-01 11:43:22