0
public String[] geefAlleTemplateNamen(String[][] templateLijst){
    String[] lijst = new String[templateLijst.length];
    for(int i = 0; i < templateLijst.length; i++){
        lijst[i] = templateLijst[i][0];
    }
return lijst;
}

The code above returns an array 'lijst'.

System.out.println(geefAlleTemplateNamen(templateLijst));

With this piece of code I tried to print that array, but it prints the location of the array. I know this can be solved by importing Java.util.Arrays, but I am not allowed to do this (school project), is there any way to solve this?

Thank you!

user3165926
  • 93
  • 3
  • 9
  • 6
    Iterate through the elements and print them out. – Sotirios Delimanolis Jan 06 '14 at 16:00
  • 2
    And the JDK is open source. You can see how this [method](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Arrays.java#Arrays.toString%28java.lang.Object%5B%5D%29) is implemented and inspire yourself. – Alexis C. Jan 06 '14 at 16:03
  • possible duplicate of [Simplest way to print an array in Java](http://stackoverflow.com/questions/409784/simplest-way-to-print-an-array-in-java) Look at the solutions near the bottom (using for loops and for each loops) – But I'm Not A Wrapper Class Jan 06 '14 at 16:10

2 Answers2

3

The simplest and easiest way to do this is to throw your array into a for loop.

for (int i = 0; i < lijst.length; i++) { System.out.println(lijst[i]); }

Printing the array itself should and will print its memory location, and you'll want to access each member of the array individually instead.

Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76
Drifter64
  • 1,103
  • 3
  • 11
  • 30
0

Easiest solution would be,

for(String s: lijst)
{
    System.out.println(s);
}
G.S
  • 10,413
  • 7
  • 36
  • 52
Patrick J Abare II
  • 1,129
  • 1
  • 10
  • 31