The Set Value of the list, which is related to the location of the variable (the result varies greatly due to the change of the variable range)

Source: Internet
Author: User

The result we want is:

[Regntypecharge: NULL, null, 1, null,]
[Regntypecharge: NULL, null, hehe, null,]
Com. [email protected] addbf1
Com. [email protected] 42e816

The required code is:

Package com. kompakar. eHealth. server. regn. mstr. Common. Service. impl;

Import java. util. arraylist;
Import java. util. List;

Import com. kompakar. eHealth. model. Bridge. Bo. regntypecharge;
Import com. kompakar. eHealth. model. regn. mstr. Common. View. regntypechargeview;

Public class test {

/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){

Regntypecharge BO = new regntypecharge ();
Bo. setvisittype ("1 ");
Regntypecharge bo2 = new regntypecharge ();
Bo2.setvisittype ("hehe ");

List <regntypecharge> List = new arraylist <regntypecharge> ();
List. Add (BO );
List. Add (bo2 );


List <regntypechargeview> list2 = new arraylist <regntypechargeview> ();

// Regntypechargeview view = new regntypechargeview ();
For (INT I = 0; I <list. Size (); I ++ ){
Regntypechargeview view = new regntypechargeview ();
View. setregntypecharge (list. Get (I ));
List2.add (View );

}

System. Out. println (list2.get (0). getregntypecharge ());
System. Out. println (list2.get (1). getregntypecharge ());
System. Out. println (list2.get (0 ));
System. Out. println (list2.get (1 ));

}

}

 

If you write this statement:

Package com. kompakar. eHealth. server. regn. mstr. Common. Service. impl;

Import java. util. arraylist;
Import java. util. List;

Import com. kompakar. eHealth. model. Bridge. Bo. regntypecharge;
Import com. kompakar. eHealth. model. regn. mstr. Common. View. regntypechargeview;

Public class test {

/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){

Regntypecharge BO = new regntypecharge ();
Bo. setvisittype ("1 ");
Regntypecharge bo2 = new regntypecharge ();
Bo2.setvisittype ("hehe ");

List <regntypecharge> List = new arraylist <regntypecharge> ();
List. Add (BO );
List. Add (bo2 );


List <regntypechargeview> list2 = new arraylist <regntypechargeview> ();

Regntypechargeview view = new regntypechargeview ();
For (INT I = 0; I <list. Size (); I ++ ){
// Regntypechargeview view = new regntypechargeview ();
View. setregntypecharge (list. Get (I ));
List2.add (View );

}

System. Out. println (list2.get (0). getregntypecharge ());
System. Out. println (list2.get (1). getregntypecharge ());
System. Out. println (list2.get (0 ));
System. Out. println (list2.get (1 ));

}

}

This will result in

[Regntypecharge: NULL, null, hehe, null,]
[Regntypecharge: NULL, null, hehe, null,]
Com. [email protected] addbf1
Com. [email protected] addbf1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.