Java inserts an object and JS at the specified position in the list collection method __js

Source: Internet
Author: User

Java inserts a piece of data into the collection at the specified location:

List<string> list =new arraylist<> ();
List.add ("a");
List.add ("B");
List.add ("C");
//...
At this point, list ={a,b,c}

//insert "Please select"
list.add (0, "Please select") in the 0 of the list;
At this point, list={"Please select", A, B, C}, and a will not be replaced, just use backward to move a

JS: Inserts a piece of data into the array at the specified location: Use JS's Splice () method to add/remove items to/from the array, please read the brochure

var ar =[' b ', ' C ', ' d ', ' e ']
//to AR 0 position insert ' a '
ar.splice (0,0, ' a ')//At this time ar =[a,b ...]
Insert to AR 1 position ' Please select '
ar.splice (1, 0, ' Please select ')//At this time ar=[' a ', ' Please choose ', b ...]


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.