0

I know about the working of a list. when i make the following code its working fine but i cant access its values and i know what are the values in it but following output is showing which is wrong.

 List<StringArray> searchresponse = searchContent(data, pasta, chan, Type, arrS, arrk);
System.out.print(searchresponse);

this output =
[net.java.dev.jaxb.array.StringArray@787582d3] is not correct. How to show the items which are coming in response of that function which is called ?

2 Answers2

0

System.out.print(/*Object*/ o) is equivalent to System.out.print(/*Object*/ o.toString())

In your case o is searchresponse

[net.java.dev.jaxb.array.StringArray@787582d3]

This is the default toString() behaviour.

public String More ...toString() {
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
}

To verify, try this:

String s = searchresponse.toString();
System.out.println(s);// prints net.java.dev.jaxb.array.StringArray@HEXCODE
rocketboy
  • 9,573
  • 2
  • 34
  • 36
  • I tried this but [net.java.dev.jaxb.array.StringArray@787582d3] this is the wrong output. the accurate output is some items which should be shown – user2674221 Aug 12 '13 at 08:52
0

Whenever we try to print objects, compiler will find toString() method in Object class and produce string representation of objects.You will have to override this method to get the actual values of instance variables.

class A
  { 
     String name;
     int id;
     A(String name, int id)
       {
          this.name=name;
          this.id=id;
       }
  public String toString()
      {
        return (name+" "+id);
      }
  public static void main (String ...a)

    { 
       List<A> list = new ArrayList<A>();
       A o = new A("a",1);
       A o1= new A ("b",2);
       list.add(o);
       list.add(o1);
       System.out.println(list); 

   }

 }

Output

[a 1, b 2]
Malwaregeek
  • 2,274
  • 3
  • 15
  • 18