Js implements the ArrayList function and js implements the arraylist function.

Source: Internet
Author: User

Js implements the ArrayList function and js implements the arraylist function.
1. Summary of the ArrayList Method

Constructor abstract ArrayList () constructs an empty list with an initial capacity of 10. ArrayList (Collection <? Extends E> c) constructs a list of elements that contain the specified collection. These elements are arranged in the order returned by the collection iterator. ArrayList (int initialCapacity) constructs an empty list with the specified initial capacity. Method abstract booleanadd (E e) adds the specified element to the end of this list. Voidadd (int index, E element) inserts the specified element into the specified position in this list. BooleanaddAll (Collection <? Extends E> c) add all elements in the collection to the end of the list in the order returned by the iterator of the specified collection. BooleanaddAll (int index, Collection <? Extends E> c) inserts all elements in the specified collection into the list starting from the specified position. Voidclear () removes all elements from this list. Objectclone () returns a superficial copy of The ArrayList instance. Booleancontains (Object o) returns true if the list contains the specified element. VoidensureCapacity (int minCapacity) increases the capacity of this ArrayList instance if necessary to ensure that it can accommodate at least the number of elements specified by the minimum capacity parameter. Eget (int index) returns the element at the specified position in this list. IntindexOf (Object o) returns the index of the specified element that appears for the first time in this list, or-1 if this list does not contain elements. BooleanisEmpty () if there is no element in this list, true intlastIndexOf (Object o) is returned to the index of the last specified element in this list, or if this list does not contain an index, -1 is returned. Eremove (int index) removes the elements at the specified position in this list. Booleanremove (Object o) removes the specified Element (if any) that appears for the first time in this list ). Protected voidremoveRange (int fromIndex, int toIndex) removes all elements in the list between fromIndex (included) and toIndex (excluded. Eset (int index, E element) replaces the element at the specified position in this list with the specified element. Intsize () returns the number of elements in this list. Object [] toArray () returns an array containing all elements in the list in the appropriate order (from the first to the last element. <T> T [] toArray (T [] a) returns an array containing all the elements in the list in the appropriate order (from the first to the last element; the runtime type of the returned array is the runtime type of the specified array. VoidtrimToSize (): Adjust the capacity of the ArrayList instance to the current size of the list.


2. js implementation of some functions
<Html> <script type = "text/javascript" src = "json. js "> </script> 





Call the java function in js to return the arraylist type. How can I convert it to the array type in js?

Js only has the var type, regardless of the Low-hour group or other types similar to the String or int type in java. If js wants to obtain the array in ava, use json.
Convert a set to json in java code:
@ RequestMapping (value = "/slick/home ")
Public void homePage (HttpServletResponse response) throws IOException {
String json = null;
Response. setContentType ("application/json ");
PrintWriter out = response. getWriter ();
Gson gson = new GsonBuilder (). serializeNulls (). setDateFormat (DateFormat. LONG)
. SetPrettyPrinting (). setVersion (1.0). create ();
List <Integer> list = new ArrayList <Integer> ();
For (int I = 0; I <10; I ++ ){
List. add (I );
}
JSONArray ja = JSONArray. fromObject (mes );
Json = gson. toJson (ja. toString ());

Out. print (json );
}

Code parsed in js:
Function tested (){
JQuery. getJSON ("$ {path}/slick/home? Time = "+ new Date (). getTime (),
Function (items ){
Var output = [];
Output. push ('<option value = "">-select-</option> ');
JQuery. each (items, function (I, item ){
Output. push ('<option value = "' + item + '">' + item + '</option> ');
});
('{'{Nextunit}.html (output. join (''));
Certificate ('{'{nextunit}.css ('display ','');
});
}

Hope to help you.

How can I read a java ArrayList array as a string in JS Code?

Use the c: foreach label to read data.

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.