1

When I run my program and type in the inputs the result is [Ljava.lang.String;@5d79a22d I'm not sure what this means or why it is happening. This is part of my program:

Scanner s = new Scanner(System.in);
//first input
System.out.println("Enter your first input: ");
String first = s.nextLine();
String[] firstsplit = first.split(", ");
//second input
System.out.println("Enter your second input: ");
String second = s.nextLine();
String[] secondsplit = second.split(", ");
//third input
System.out.println("Enter your third input: ");
String third = s.nextLine();
String[] thirdsplit = third.split(", ");
//fourth input
System.out.println("Enter your fourth input: ");
String fourth = s.nextLine();
String[] fourthsplit = fourth.split(", ");
//fifth input
System.out.println("Enter your fifth input: ");
String fifth = s.nextLine();
String[] fifthsplit = fifth.split(", ");
//declares array of numbers for whites with given numbers

String[] subset1white= Arrays.copyOfRange(firstsplit, 1, Integer.parseInt(firstsplit[0]));
System.out.println(subset1white);

Any help would be appreciated.

Natrocks
  • 114
  • 1
  • 2
  • 10
  • 6
    Use `System.out.println(Arrays.toString(subset1white));` – Alexis C. Mar 14 '14 at 15:29
  • 1
    What you're seeing is the native implementation of .toString() on an array object. Suggest you either follow ZouZou's advice, or learn how to loop through the array printing each item on a separate line. – jgitter Mar 14 '14 at 15:31

2 Answers2

3

This because you're calling toString method of a regular array

Try this:

System.out.println(Arrays.toString(subset1white));
Salah
  • 8,567
  • 3
  • 26
  • 43
1

You should use the Arrays.toString(Object[]) method, like this:

System.out.println(Arrays.toSting(subset1white));

Make sure to put

import java.util.Arrays;

at the top of your class. By default, printing an array will use Object's toString() method, which returns

getClass().getName() + '@' + Integer.toHexString(hashCode())

Arrays.toString(Object[]) will return a string like this:

[abc, 123, def, 456]
The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75