Public class getspecifiedelementfromalist {
Public static void main (string [] ARGs ){
List <pojo> List = new arraylist <pojo> ();
Pojo A = new pojo ();
A. setkey ("AAA ");
A. setcontent ("aaa111111 ");
Pojo B = new pojo ();
B. setkey ("BBB ");
B. setcontent ("bbb222222 ");
List. Add ();
List. Add (B );
// So, we're going to find out where it is. I mean the element which key is 'bbb '.
// If you do it with the original object, everything seems OK.
Int idx = List. indexof (B );
System. Out. println (idx); // you can get a '1' here.
// But if you do it with a brand new object
// Containing the same value with the original one...
Pojo c = new pojo ();
// Like this...
C. setkey ("BBB ");
C. setcontent ("bbb222222 ");
Idx = List. indexof (C );
System. Out. println (idx); // you'll get nothing but '-1 '.
// Which means it is not supposed to be used like this at all.
}
}