/*
Collection
|--List: Elements are ordered , Elements can be repeated . Because the set system has an index .
|--ArrayList: The underlying data structure uses array structure . characteristic : Fast query . But the addition and deletion are a little slower . Thread out of sync .
|--LinkedList: Linked list data structure used in the bottom layer . characteristic : The speed of adding and deleting is very fast , The query is a little slow . Thread out of sync .
|--Vector: The bottom layer is array data structure . Thread synchronization . By ArrayList Replaced the . Because it's inefficient . |--Set: The elements are disordered , Elements cannot be repeated .、 List:
Unique method . Any method that can operate the corner marker is unique to this system . increase
add(index,element);
addAll(index,Collection); Delete
remove(index); Change
set(index,element);
check
get(index):
subList(from,to);
listIterator();
int indexOf(obj): Gets the location of the specified element .
ListIterator listIterator(); List Set specific iterators .ListIterator yes Iterator Sub interface of . At iteration time , You can't manipulate elements in a collection through the method of a collection object .
Because it's going to happen ConcurrentModificationException abnormal . therefore , In iterators , You can only use the pass operation element of an iterator , But Iterator The method is limited ,
You can only judge elements , Take out , Deleted actions ,
If you want to do something else like add , Modify etc. , You need to use its sub interfaces ,ListIterator. The interface can only be accessed through List A collection of listIterator Method to get . */ import java.util.*;
class ListDemo
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void method()
{ ArrayList al = new ArrayList(); // Additive elements
al.add("java01");
al.add("java02");
al.add("java03"); sop(" The original set is :"+al);
// Add the element in the specified position .
al.add(1,"java09"); // Deletes the element at the specified location .
//al.remove(2); // Modifying elements .
//al.set(2,"java007"); // Get the elements through the corner marks .
sop("get(1):"+al.get(1)); sop(al); // Get all the elements .
for(int x=0; x<al.size(); x++)
{
System.out.println("al("+x+")="+al.get(x));
} Iterator it = al.iterator(); while(it.hasNext())
{
sop("next:"+it.next());
} // adopt indexOf Get the location of the object .
sop("index="+al.indexOf("java02")); List sub = al.subList(1,3); sop("sub="+sub);
} public static void main(String[] args)
{ // Show me the list iterator .
ArrayList al = new ArrayList(); // Additive elements
al.add("java01");
al.add("java02");
al.add("java03"); sop(al); ListIterator li = al.listIterator(); //sop("hasPrevious():"+li.hasPrevious()); while(li.hasNext())
{
Object obj = li.next(); if(obj.equals("java02"))
//li.add("java009");
li.set("java006"); } while(li.hasPrevious())
{
sop("pre::"+li.previous());
}
//sop("hasNext():"+li.hasNext());
//sop("hasPrevious():"+li.hasPrevious()); sop(al); /*
// In the iteration process , Ready to add or remove elements . Iterator it = al.iterator(); while(it.hasNext())
{
Object obj = it.next(); if(obj.equals("java02"))
//al.add("java008");
it.remove();// take java02 The reference to was removed from the collection . sop("obj="+obj); }
sop(al);
*/ }
}

java aggregate _collection A subinterface list The unique method of ,ArrayList Class embodies more related articles

  1. Java Basics -Collection Sub interface Set Interface

    Java Basics -Collection Sub interface Set Interface author : Yin Zhengjie Copyright notice : Original works , Declined reprint ! Otherwise, the legal liability will be investigated . Study Collection Interface , Remember Collection Duplicate elements can be stored in , Can also be ...

  2. Java Basics -Collection Sub interface List Interface

    Java Basics -Collection Sub interface List Interface author : Yin Zhengjie Copyright notice : Original works , Declined reprint ! Otherwise, the legal liability will be investigated . We have mastered Collection After using the interface , Look again. Collection Interface ...

  3. Java Collections framework ——List Interface

    The third stage JAVA Learning common objects Collections framework --List Interface According to the inheritance system of the set framework , Let's start with Collection Medium List The interface begins to learn ( One ) Overview and function (ArrayList demonstration ) (1) summary L ...

  4. Java Gather them together Collection Interface

    java The collection of is divided into three interfaces , Namely Collection,Map,Iterator, Collection interfaces and classes in java.util In bag , This time, we mainly introduce one of the three interfaces Collection Interface . some Collection Permit ...

  5. Java Collections framework ——Map Interface

    The third stage JAVA Learning common objects Collections framework --Map aggregate In real demand , We often encounter such problems , In a lot of data , Look for some information by its number , To view or modify , For example, through the student number query student information . What we're talking about today is ...

  6. Java Collections framework ——Set Interface

    The third stage JAVA Learning common objects Collections framework --Set Interface List A set is characterized by order , Repeatable , Is there such a disorder , And a unique set of elements ?(HashSet ) This involves what we are going to talk about today Set aggregate ...

  7. Java Assembly and LIst Interface

    One . The concept of set 1. summary : Before learning to assemble , Let's first recall a feature of an array --- Arrays have a fixed length , Define an array : int[] array = new int[]; In the case of variable data length , There's a set , ja ...

  8. Java Collection framework top level interface collectiion Interface

    How to use iterators Usually , You'll want to traverse the elements of a collection . for example , Show each element in the collection . Generally speaking, traversal array is based on for Loop or enhance for, These two methods can also be used in the collection framework , But another way is to use iterators to traverse the collection ...

  9. java Part of the interface to the collection

    Interface Collection<E> public interface Collection<E>extends Iterable<E> Collection hierarchy ...

Random recommendation

  1. AutoComplete

    aspx page Files that need to be referenced : <link rel="stylesheet" type="text/css" href="css/jquery. ...

  2. Asynchronous event call component inside process Async-Event

    Project coordinates :https://github.com/cncduLee/async-event async-event Asynchronous event call component inside process What problem to solve : Speed up service processing efficiency . Provides process level event publishing and heterogeneous ...

  3. .net Submit HTML Elements to the background , encounter Request Report errors Solution

    about .NET MVC For projects , stay Controller Corresponding Action Label the method : [ValidateInput(false)] stay MSDN On :HttpRequest  Class uses input validation flags to track ...

  4. hibernate Study ——Set Set configuration

    Set Configuration of collections Data table creation : Table relationship an employee has multiple identities create table EMPLOYEE ( id INT NOT NULL auto_increment, first_name VAR ...

  5. CGAffineTransform Radial transformation analysis That is matrix transformation

    Reprinted from ;http://www.cocoachina.com/bbs/3g/read.php?tid=151136 Matrix multiplication A B Multiplication is necessary A The number of columns is equal to B The number of rows is defined , The result is a A That's ok B Columns of the matrix C,C Every ...

  6. javascript rounding tofixed

    //toFixed() The method can be used to Number A number rounded to a specified number of decimal places . $("#renjunlirun").val(zongLiRun.toFixed(2));// amount of money

  7. ESP- mobile phone -- Two way communication mode

    1 AP Accept cell phones 2 STA( The password is fixed ) Connect the router ,AP Accept cell phones 3 STA( The password is flexible ) Connect the router ,AP Accept cell phones 1 AP Accept cell phones #include <ESP8266WiFi.h>   ...

  8. 2-( Basic introduction )Air202 Download the development guide ( to Air202 Download the first program )

    http://www.cnblogs.com/yangfengwu/p/8887933.html The data link link :https://pan.baidu.com/s/1-SRfsKGQ7rZVvFmp1O ...

  9. adopt .json() Convert the string returned by the server into a dictionary

  10. python Next use epoll

    Reference: http://blog.csdn.net/hehe123456ZXC/article/details/52526670 Because I want to learn how to use epoll Write server , So I found an introduction ...