When compiling this below code I'm receiving this output. I'm not sure where I'm making the mistake as the output should be the content of the array rather than its address. Appreciate any help!!
import java.util.*;
public class insert_intervals{
public static void main(String[] args) {
int[][] intervals = {{1, 3} , {6 , 9}};
int[] newInterval = {2, 5};
List<int[]> ans = new ArrayList<>();
int newBegin = newInterval[0];
int newEnd = newInterval[1];
for(int[] interval : intervals){
int currentBegin = interval[0];
int currentEnd = interval[1];
if((currentBegin < newBegin && currentEnd < newEnd) || (currentBegin > newBegin && currentEnd > newEnd)){
ans.add(interval);
}else if(currentEnd >= newBegin){
newBegin = Math.min(currentBegin, newBegin);
newEnd = Math.max(currentEnd, newEnd);
int[] arr = {newBegin, newEnd};
ans.add(arr);
}
}
for(int[] ar : ans){
System.out.println(ar);
}
}
}
Output : [I@2c7b84de [I@3fee733d
I tried to get the elements of the array using for each loop but it provides me the address of the array. I have tried in online compilers as well and receiving similar output.