ArrayList set and arraylist set sorting

Source: Internet
Author: User

ArrayList set and arraylist set sorting

// Do not forget to reference the namespace using System when using ArrayList. collections; // first import the namespace // 01. add Method add method // tell memory, I want to store content ArrayList list = new ArrayList (); list. add ("Haha"); list. add (""); list. add ("Haha"); // 02. print the name of each person foreach (Object item in list) {Console. writeLine ("name:" item + "");} // 03. obtain the information Console separately. writeLine (list [0]); // obtain the subscript // 04. delete hehaoxi list. remove ("Haha"); // Delete (Delete content) list. removeAt (1); // Delete the Console. writeLine ("====== === After deletion ========= "); foreach (Object item in list) {Console. writeLine ("name:" + item + "");} // 05. insert to the specified position (add to append, insert to specified insert) list. insert (1, "er"); Console. writeLine ("========= after insert ======="); foreach (Object item in list) {Console. writeLine ("name:" + item + "");} // 06. judge whether or not bool flag = list is in the Set named list. contains ("er Er"); Console. writeLine (flag); // 07. modify it to the number of elements in the array: XX. length // number of elements in the Set: xx. C Ount for (int I = 0; I <list. count; I ++) {// judge whether there is, and then modify if (list. contains ("er") {// exist, modify if (list [I]. equals ("er Er") {// modify the reassignment list [I] = "Haha"; break ;}} else {Console. writeLine ("No such person, how to modify ??? ") ;}} Console. writeLine ("========= after modification ========"); foreach (Object item in list) {Console. writeLine ("name:" + item + "");}

 

Related Article

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.