Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common methods of java list?

Shulou Source: shulou.com Published: 2022-06-03 05:58:02 10月03日 Update

In this issue, the editor will bring you about what are the common methods of java list. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1.list intercepts the specified part

List sublist = new ArrayList (); sublist = new ArrayList (alist.subList (2,4))

two。 Update content at the specified location

Public ArrayList attrs = new ArrayList (); / / layer attribute attrs.set (position, "string")

3. Determine if there are duplicates in the Arraylis

Public static void main (String [] args) {List list = new ArrayList (); list.add ("aa"); list.add ("bb"); list.add ("cc"); list.add ("dd"); list.add ("bb"); list.add ("ee"); list.add ("dd"); list.add ("ff"); String temp = ""; for (int I = 0; I < list.size ()-1; iTunes +) {temp = list.get (I) For (int j = I + 1; j < list.size ()) {if (temp.equals (list.get (j) {System.out.println ("th" + (I + 1) + "repeat with" + (j + 1) + ", the value is:" + temp);}}

Mutual Transformation between list and Array in 4.java

1) convert an array to a collection

Arrays can be converted to List, but other functions cannot be used except for display functions, because the list obtained through the conversion does not know what type it is, and can be assigned by the construction method of the collection to use other functions:

String [] names = {"Liu Bei", "Cao Cao", "Zhuge Liang"}; List list1 = Arrays.asList (names); list1 = new ArrayList (list1)

2) convert the collection to an array

Object [] ary1 = list3.toArray (new String [list3.size ()]); / / System.out.println (Arrays.toString (ary1))

Convert 5.Hashmap to arraylist

HashMap hashMap = iMarkerService.getBaiduMarkerMap (); ArrayList markers = new ArrayList (hashMap.values ())

6. Convert to the string join

List userParms=new ArrayList (); String userSql = String.join ("AND", userParms)

7. Sort

Collections.sort (warnRes, new Comparator () {/ / sort by final insurance date public int compare (WarnRes warnRes0, WarnRes warnRes1) {return warnRes1.getZbrq () .compareTo (warnRes0.getZbrq ());}})

These are the common methods of java list shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Content array method function commonly used analysis sorting professional small and medium location rich in content can be made through characters strings that is attributes articles dates and more. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi MariaDB OPPO Reno Shulou Technology