Java Reference
In-Depth Information
55
/** Remove the last node and
56
* return the object that is contained in the removed node. */
57
public E removeLast() {
removeLast
58
// Implemented in Section 24.4.3.5, so omitted here
59 }
60
61 @Override /** Remove the element at the specified position in this
62 * list. Return the element that was removed from the list. */
63
public E remove( int index) {
remove
64
// Implemented earlier in Section 24.4.3.6, so omitted here
65 }
66
67 @Override
68 public String toString() {
69 StringBuilder result = new StringBuilder( "[" );
70
71 Node<E> current = head;
72 for ( int i = 0 ; i < size; i++) {
73 result.append(current.element);
74 current = current.next;
75 if (current != null ) {
76 result.append( ", " ); // Separate two elements with a comma
77 }
78 else {
79 result.append( "]" ); // Insert the closing ] in the string
80 }
81 }
82
83
toString
return result.toString();
84 }
85
86 @Override /** Clear the list */
87 public void clear() {
88 size = 0 ;
89 head = tail = null ;
90 }
91
92 @Override /** Return true if this list contains the element e */
93 public boolean contains(E e) {
94 System.out.println( "Implementation left as an exercise" );
95
clear
contains
return true ;
96 }
97
98 @Override /** Return the element at the specified index */
99 public E get( int index) {
100 System.out.println( "Implementation left as an exercise" );
101
get
return null ;
102 }
103
104 @Override /** Return the index of the head matching element
105 * in this list. Return -1 if no match. */
106 public int indexOf(E e) {
107 System.out.println( "Implementation left as an exercise" );
108
indexOf
return 0 ;
109 }
110
111 @Override /** Return the index of the last matching element
112 * in this list. Return -1 if no match. */
113 public int lastIndexOf(E e) {
114 System.out.println( "Implementation left as an exercise" );
lastIndexOf
 
Search WWH ::




Custom Search