【DataStructure】Descriptioin and usage of List
2014-08-10 22:07
387 查看
Statements: This blog was written by me, but most of content is quoted from book【Data Structure with Java Hubbard】
【Description】
Alistis a collection of elements that are accessible sequentially: the first element, followed by the second element, followed by the third element, and so on.This is called sequential accessor linked access(as opposed to direct or indexed access)
【Interface】
From the JCF inheritance hierarchy , you can see that the Queue, Deque, and Setinterfaces all extend the Listinterface. Consequently, all of the List,Queue, Deque, and Setclasses implement the Listinterface. This includes the concrete classes: ArrayList, Vector, LinkedList, PriorityQueue, ArrayDeque,EnumSet,HashSet,LinkedHashSet,and TreeSet.the JCF provides both linked and indexed implementations of the Listinterface: the LinkedListclass uses sequential access, while the ArrayListclass provides direct access.
【Demo】
This demo is related to subList.package com.albertshao.ds.list; // Data Structures with Java, Second Edition // by John R. Hubbard // Copyright 2007 by McGraw-Hill import java.util.*; public class TestSubList { public static void main(String[] args) { List<String> list = new ArrayList<String>(); Collections.addAll(list, "A","B","C","D","E","F","G","H","I","J"); System.out.println(list); System.out.println("list.subList(3,8): " + list.subList(3,8)); System.out.println("list.subList(3,8).get(2): " + list.subList(3,8).get(2)); System.out.println("list.subList(3,8).set(2,\"B\"):"); list.subList(3,8).set(2, "B"); System.out.println(list); System.out.println("list.indexOf(\"B\"): " + list.indexOf("B")); System.out.println("list.subList(3,8).indexOf(\"B\"): " + list.subList(3,8).indexOf("B")); System.out.println(list); System.out.println("Collections.reverse(list.subList(3,8)):"); Collections.reverse(list.subList(3,8)); System.out.println(list); System.out.println("Collections.rotate(list.subList(3,8), 2):"); Collections.rotate(list.subList(3,8), 2); System.out.println(list); System.out.println("Collections.fill(list.subList(3,8), \"X\"):"); Collections.fill(list.subList(3,8), "X"); System.out.println(list); list.subList(3,8).clear(); System.out.println(list); } }【Result】
[A, B, C, D, E, F, G, H, I, J] list.subList(3,8): [D, E, F, G, H] list.subList(3,8).get(2): F list.subList(3,8).set(2,"B"): [A, B, C, D, E, B, G, H, I, J] list.indexOf("B"): 1 list.subList(3,8).indexOf("B"): 2 [A, B, C, D, E, B, G, H, I, J] Collections.reverse(list.subList(3,8)): [A, B, C, H, G, B, E, D, I, J] Collections.rotate(list.subList(3,8), 2): [A, B, C, E, D, H, G, B, I, J] Collections.fill(list.subList(3,8), "X"): [A, B, C, X, X, X, X, X, I, J] [A, B, C, I, J]
相关文章推荐
- Could not find a price list in Ordered UOM xxx and Primary UOM of the item
- 【DataStructure】The description and usage of Stack
- 【DataStructure】Charming usage of Set in the java
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- [Err] 1055 - Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- How to Output a List of Files to a File and Sort Them in Linux
- List of free and open source operating systems (In alphabetic order, 345)
- jdbc4.MySQLSyntaxErrorException:Expression #2 of SELECT list is not in GROUP BY clause and contains
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column '
- usage of fscanf and other read functions in C/C++
- Get a List of Keys From a Dictionary in Both Python 2 and Python 3
- 【DataStructure】Charming usage of Set in the java
- ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate
- Row wise initialized variable in OBIEE 11g and VALUELISTOF function
- Get a list of network interfaces and their IP addresses in C
- 106.Examine the data in the LIST_PRICE and MIN_PRICE columns of the PRODUCTS table:
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i