43

How can I print the arr variable in the log to see the results of the array thanks,

 public void onClick(View v) {
     if(v.getId()==R.id.buttonone)
     {
          genrandom grandom =new genrandom();
          int[] arr=new int[50];
          arr = new  gen_random_number().genrandom(arr, yourXvalue);
     }
 }
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
user1760556
  • 489
  • 1
  • 4
  • 4

6 Answers6

143

You can use Arrays.toString

Log.d("this is my array", "arr: " + Arrays.toString(arr));
// or
System.out.println("arr: " + Arrays.toString(arr));

Or, if your array is multidimensional, use Arrays.deepToString()

String[][] x = new String[][] {
    new String[] { "foo", "bar" },
    new String[] { "bazz" }
};
Log.d("this is my deep array", "deep arr: " + Arrays.deepToString(x));
// or
System.out.println("deep arr: " + Arrays.deepToString(x));
// will output: [[foo, bar], [bazz]]
Alex
  • 25,147
  • 6
  • 59
  • 55
6

Very simple use for each loop much fast then normal for (incremental) loop.

for(String log : array)
{
  Log.v("Tag",log);
}
Mohd Mufiz
  • 2,236
  • 17
  • 28
1

You can use for each loop

for(int x: arr){
Log.d(tag,"x:"+x);
}
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
0

Try this way:

for (int i =0 ;i<arr.length;i++)
{
   Log.v("Array Value","Array Value"+arr[i]);
}
Echilon
  • 10,064
  • 33
  • 131
  • 217
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39
0

Try this :

for (int i = 0; i < arr.length; i++) {
   Log.d(TAG, arr[i]);
}

What we are doing here is iterating over the array using the for loop to print logcat. Log cat output can be done with Log.d(..), Log.v(..) , Log.i(..) or Log.e(..). See more here.

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
0

You can also try plain old

 System.out.println()
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
Aditya K
  • 487
  • 3
  • 11