I’m working on a project that requires me to have a string representation of an array. The problem is having this duplicated code, that I’m sure can be refactored in some way, but I haven’t found one yet.
private static String printDoubleArray(String title, double[] array){
String result = title;
for (double d : array) {
result += d + " ";
}
return result;
}
private static String printIntArray(String title, int[] array){
String result = title;
for (int d : array) {
result += d + " ";
}
return result;
}
Thanks in advance.
Why not use one of the methods
Arrays.toString(...)fromjava.utilpackage?