code_junkie

Java: Array of primitive data types does not autobox

Nov 14th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. char
  2.  
  3. char[]
  4.  
  5. char ch = 'a';
  6. String chars = "abc";
  7. boolean member = chars.indexOf(ch) >= 0;
  8.  
  9. public static Integer[] boxedArray(int[] array) {
  10. Integer[] result = new Integer[array.length];
  11. for (int i = 0; i < array.length; i++)
  12. result[i] = array[i];
  13. return result;
  14. }
  15.  
  16. import java.lang.reflect.Array
  17. public static boolean isMemberOfArray(Object item, Object array)
  18. {
  19. int n = Array.getLength(array)
  20. for (int i = 0; i < n; i++) {
  21. if (Array.get(array, i).equals(item)) {
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
Add Comment
Please, Sign In to add comment