-1

How to show element of ArrayList converted to Object array by toArray methode?

I want to show array a's element (code in below) but It seem to just return address of the array. please help me ...T^T

import java.util.ArrayList;
import java.util.Arrays;


public class testworld {

    static ArrayList<history> histories =new ArrayList<history>();

    public static void main(String[] args) {    

    history m1 =new history();
    m1.setAmount(""+0);
    m1.setUse("use");
    m1.setDate("date");
    m1.setTime("time");

    history m2 =new history();
    m2.setAmount(""+0);
    m2.setUse("use2");
    m2.setDate("date2");
    m2.setTime("time2");

    history m3 =new history();
    m3.setAmount(""+0);
    m3.setUse("use3");
    m3.setDate("date3");
    m3.setTime("time3");


    histories.add(0,m1);
    histories.add(1,m2);
    histories.add(2,m3);

    Object[] a = histories.toArray();

    System.out.println(Arrays.toString(a));
    System.out.println(a[0]);
    System.out.println(a[1]);
    System.out.println(a[2]);

    System.out.print(a);
    System.out.println(a);

    }
}

[notepad.history@15db9742, notepad.history@6d06d69c, notepad.history@7852e922]

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
JeonJiwon
  • 13
  • 2

1 Answers1

1

What you see there is the content of the array. You must overwrite the toString() method in the history class to see some useful information. The code you are asking for is

history[] a = new history[histories.size()];
a = histories.toArray(a);

I understand you are a beginner at java. Please read the javadocs or do some research before posting any further questions on stackoverflow. Also, read the java naming conventions. It 's History not history. Always use camel-case.