Can I override the toString() method of an Array object.
So that a customised message will be printed with System.out.println
String[] strArr={"one","two","three"};
System.out.println(strArr);
--> now it is printing "java.lang.String;@hashcode"
i would like to be print "one two three" (i.e space separated values
of the elements) with the statement System.out.println(strArr);
For this is there any way of overriding toString() of the String[] array object.
Currently I am managing with
static String printArray(Object[] objArr) {
String str="";
for (int i=0; i<objArr.length; i++){
str=str + objArr[i]+" ";
}
return str;
}
and calling as printArray(strArr);
but this is ofcourse a bit tedious.
Thanks in Advance.
Madhu_1980