cmavuleti
Posts: 2
Joined: Fri Aug 23, 2019 7:40 pm

array values not printing

Thu Oct 17, 2019 1:31 am

I want to print a one-dimensional array.
But, it is printing as

Out put : [Ljava.lang.String;@15db9742'

But Expected Out put: ["a", "b", "c", "d", "e" ]

My programs is:

Code: Select all

public class PrintArray {

	String[] values = new String[] { "a", "b", "c", "d", "e" };

	void print() {
		System.out.println(values);
	}

	public static void main(String[] s) {
		PrintArray object = new PrintArray();
		object.print();
	}

}
How can I solve the above java programming issue?

User avatar
addeswe
Posts: 29
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Re: array values not printing

Thu Oct 17, 2019 11:27 am

Code: Select all

import java.util.Arrays;

public class Main {

	static String[] values = new String[] { "a", "b", "c", "d", "e" };

	static void print() {
		System.out.println(Arrays.asList(values));
	}

	public static void main(String[] s) {
    print();
	}

}
Here is a working example. :-)
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

Return to “Java”