SortedArrayList extends ArrayList<E> { public SortedArrayList(Comparator<? super E> c) { comparator = c; } SortedArrayList(Comparator<? super E> c);  SortedArrayList();  SortedArrayList(Collection<? extends E> c); Comparator getComparator(); @Override boolean add(E o); @Override boolean addAll(Collection<? extends E> c); int findInsertionPoint(E o); @Override @Deprecated void add(int index, E element); @Override @Deprecated E set(int index, E element); @Override @Deprecated boolean addAll(int index, Collection<? extends E> c);  }
@Test public void sortedArrayList() { SortedArrayList<String> list = MoreLists.createSortedArrayList(); list.add("9"); list.add("1"); list.add("6"); list.add("9"); list.add("3"); assertThat(list).containsExactly("1", "3", "6", "9", "9"); list.remove(2); assertThat(list).containsExactly("1", "3", "9", "9"); assertThat(list.contains("3")).isTrue(); assertThat(list.contains("2")).isFalse(); try { list.add(1, "2"); fail("should fail before"); } catch (Throwable t) { assertThat(t).isInstanceOf(UnsupportedOperationException.class); } try { list.set(1, "2"); fail("should fail before"); } catch (Throwable t) { assertThat(t).isInstanceOf(UnsupportedOperationException.class); } SortedArrayList<String> list2 = MoreLists.createSortedArrayList(Ordering.natural()); list2.addAll(ListUtil.newArrayList("3", "1", "2")); assertThat(list2).containsExactly("1", "2", "3"); }