Содержание
- 2. Коллекции 5. Списки
- 3. Списки
- 4. Интерфейс List public interface List extends Collection { boolean add(E e); void add(int index, E element);
- 5. Интерфейс RandomAccess public interface RandomAccess { } I
- 6. Реализации интерфейса List
- 7. Класс EmptyList
- 8. Класс EmptyList public class Collections { public static final List EMPTY_LIST = new EmptyList(); public static
- 9. Использование EmptyList public class EmptyListDemo { public static void main(String[] args) { List staff = Collections.emptyList();
- 10. Сравнение производительности для пустого List public class EmptyListsCompareDemo { private static final int ITERATIONS = 10000000;
- 11. Сравнение производительности для пустого List Time using ArrayList(): 312 ms Time using ArrayList(0): 188 ms Time
- 12. Класс SingletonList
- 13. Класс SingletonList public class Collections { public static List singletonList(T o) { return new SingletonList (o);
- 14. Использование SingletonList public class SingletonListDemo { public static void main(String[] args) { List staff = Collections.singletonList("Harry
- 15. Сравнение производительности для List с одним элементом public class OneValueListsCompareDemo { public static void main(String[] args)
- 16. Сравнение производительности для List с одним элементом Time using ArrayList(): 359 ms Time using ArrayList(1): 266
- 17. Класс ArrayList
- 18. Класс ArrayList public class ArrayList extends AbstractList implements List , RandomAccess, Cloneable, Serializable { private transient
- 19. Ёмкость и размер
- 20. public class ArrayListCapacityDemo { private static final int ITERATIONS = 25000000; public static void main(String[] args)
- 21. Добавление элементов
- 22. Добавление элементов public class SimpleListAddDemo { public static void main(String[] args) { List fruits = new
- 23. Добавление элементов по индексу public class ListInsertDemo { public static void main(String[] args) { List fruits
- 24. Удаление элементов
- 25. Удаление элементов public class ListRemoveDemo { public static void main(String[] args) { String[] toAdd = {
- 26. Удаление элементов List size: 10 List contents: [apple, cucumber, carrot, kiwi, potato, tomato, cucumber, orange, carrot,
- 27. Удаление элементов по индексу public class ListRemoveAtIndexDemo { public static void main(String[] args) { String[] toAdd
- 28. Удаление элементов по индексу List size: 10 List contents: [apple, cucumber, carrot, kiwi, potato, tomato, cucumber,
- 29. Позиционный доступ
- 30. Позиционный доступ public class ListGetSetDemo { public static void main(String[] args) { String[] toAdd = {
- 31. Позиционный доступ Set size: 8 Set contents: [apple, carrot, kiwi, potato, tomato, pear, cucumber, orange] Changing
- 32. Поиск
- 33. Поиск первого и последнего вхождения public class ListIndexOfDemo { public static void main(String[] args) { String[]
- 34. Поиск первого и последнего вхождения Set size: 11 Set contents: [apple, cucumber, carrot, kiwi, potato, tomato,
- 35. Поиск public class ListContainsDemo { public static void main(String[] args) { String[] toAdd = { "apple",
- 36. Поиск Set size: 8 Set contents: [apple, carrot, kiwi, potato, tomato, pear, cucumber, orange] carrot is
- 37. Класс LinkedList
- 38. Класс LinkedList public class LinkedList extends AbstractSequentialList implements List ,..., Cloneable, Serializable { private transient Entry
- 39. Позиционный доступ
- 40. Позиционный доступ public class ListGetSetDemo { public static void main(String[] args) { String[] toAdd = {
- 41. Позиционный доступ Set size: 8 Set contents: [apple, carrot, kiwi, potato, tomato, pear, cucumber, orange] Changing
- 42. Сортировка списков
- 43. Сортировка
- 44. Сортировка public class ListSortDemo { public static void main(String[] args) { String[] toAdd = { "orange",
- 45. Сортировка с Comparable public class AnotherListSortDemo { public static void main(String[] args) { List items =
- 46. Сортировка с Comparable Set contents: [name=Toaster, number=1234] [name=Kettle, number=4562] [name=Microwave oven, number=9912] [name=Coffemaker, number=2912] [name=Blender, number=1231]
- 47. Сортировка с Comparator public class ComparatorListSortDemo { public static void main(String[] args) { List items =
- 48. Сортировка с Comparator Set contents: [name=Toaster, number=1234] [name=Kettle, number=4562] [name=Microwave oven, number=9912] [name=Coffemaker, number=2912] [name=Blender, number=1231]
- 49. Сравнение производительности
- 50. Сравнение производительности public class ListsPerformanceDemo { private static final int ITERATIONS = 2000000; public static void
- 51. Сравнение производительности LinkedList time: 0 ArrayList time: 10484
- 53. Скачать презентацию