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!

3
  • 6
    Iterate through the elements and print them out. Commented Jan 6, 2014 at 16:00
  • 2
    And the JDK is open source. You can see how this method is implemented and inspire yourself. Commented Jan 6, 2014 at 16:03
  • possible duplicate of Simplest way to print an array in Java Look at the solutions near the bottom (using for loops and for each loops) Commented Jan 6, 2014 at 16:10

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Easiest solution would be,

for(String s: lijst)
{
    System.out.println(s);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.