[Operation of the JAVA100 example]004, vector (vector) object

Source: Internet
Author: User

public class Operatevector


{


/*


*<br> Method Description: Generate a 4*4 vector for use.


*<br> input Parameters:


*<br> Output variable: Vector


*<br> Other Notes:


*/


public Vector Buildvector () {


vector vtemps = new vector ();


for (int i=0;i<4;i++) {


vector vtemp = new vector ();


for (int j=0;j<4;j++) {


vtemp.addelement ("Vector (" +i+ ") (" +j+ ")");


   }


vtemps.addelement (vtemp);


   }


return vtemps;


}


/*


*<br> Method Description: Inserting Data


*<br> input parameter: Vector vtemp the data object to be inserted


*<br> input parameter: int itemp where data is inserted


*<br> input parameter: Object otemp Insert data value


*<br> Output variable: Vector results


*<br> Additional Note: If the insertion position exceeds the actual position of the instance, it returns null


*/


public vector Insert (vector vtemp,int itemp,object otemp) {


if (itemp>vtemp.size ()) {


print ("Data hyper-bounds!");


return null;


}else{


Vtemp.insertelementat (otemp,itemp);


  }


return vtemp;


}


/*


*<br> Method Description: Removing Data


*<br> input parameters: Vector vtemp object to be deleted


*<br> input parameter: int ITEMP Deletes the location of the data


*<br> Output variable: Vector


*<br> Other Notes: If you delete the data in the bounds, you will return null


*/


Public Vector Delete (Vector vtemp,int itemp) {


if (itemp>vtemp.size ()) {


print ("Data hyper-bounds!");


return null;


}else{


Vtemp.removeelementat (ITEMP);


  }


return vtemp;


}


/*


*<br> Method Description: Modifying Data


*<br> input parameters: vector vtemp to be modified


*<br> input Parameters: int ITEMP Modify the location of the data


*<br> input parameter: Object otemp Modify data value


*<br> Output variable: Vector


*<br> Other Note: If you modify the data in the location hyper-bounds, you will return null


*/


public vector updata (vector vtemp,int itemp,object otemp) {


if (itemp>vtemp.size ()) {


print ("Data hyper-bounds!");


return null;


}else{


Vtemp.setelementat (otemp,itemp);


  }


return vtemp;


}


/*


*<br> Method Description: Output information


*<br> input parameter: String stemp output Information name


*<br> input parameter: Object otemp output Information value


*<br> return variable: no


*/


public void print (String stemp,vector otemp) {


System.out.println (stemp+ "Data:");


This.print (otemp);


}


/**


*<br> Method Description: Print output (overload)


*<br> input parameter: Object Opara output


*<br> return type: No


*/


public void print (Object Opara) {


System.out.println (Opara);


}


/**


*<br> Method Description: Print output (overload)


*<br> input parameters: vector vpara display output vector objects


*<br> return type: No


*/


public void print (Vector Vpara) {


for (int i=0;i<vpara.size (); i++) {


System.out.println (Vpara.elementat (i));


   }


}


/**


*<br> Method Description: Main method, program entry


*<br> input parameters: string[] args


*<br> return type: No


*/


public static void Main (string[] args)


{


Operatevector ov = new Operatevector ();


Vector vtemp = Ov.buildvector ();


ov.print ("VTemp0", vtemp);


Vector vresult = Ov.insert (vtemp,2, "added data");


ov.print ("Vresult", vresult);


Vector vresultup = Ov.updata (vresult,2, "modified data");


ov.print ("Vresultmp", Vresultup);


Vector Vresultnow = Ov.delete (vresultup,2);


ov.print ("Vresultnow", Vresultnow);


}


}

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.