集合(二)

3.stack

 栈,继承Vector类,构造函数就是只有默认构造函数,构造空栈。

package vector;

import java.util.Enumeration;
import java.util.Stack;

public class StackClass {
public static void main(String []args)
{
    Stack <String>st=new Stack<String>();
empty()和isEmpty()一毛一样 System.out.println(st.empty()); System.out.println(st.isEmpty());
for(int i=0;i<10;i++) st.add("1"+i); for(String j:st) System.out.print(j+" "); System.out.println(); /*pop*/ 压入栈,返回这个值 System.out.println(st.pop()); /*push*/ 弹出栈,返回这个值 System.out.println(st.push("I'm")); System.out.println(st.push("Stack")); /*peek*/ 返回栈顶 System.out.println(st.peek()); Enumeration<String> e=st.elements(); while(e.hasMoreElements()) { System.out.print(e.nextElement()+" "); } System.out.println(); /*search*/ search倒着数的。。。 System.out.println(st.indexOf("18")); System.out.println(st.search("18")); } }

4.LinkedList

空构造函数和以Collection为参数的构造函数。

API函数:

boolean       add(E object)
void          add(int location, E object)
boolean       addAll(Collection<? extends E> collection)
boolean       addAll(int location, Collection<? extends E> collection)
void          addFirst(E object)
void          addLast(E object)
void          clear()
Object        clone()
boolean       contains(Object object)
Iterator<E>   descendingIterator()
E             element()
E             get(int location)
E             getFirst()
E             getLast()
int           indexOf(Object object)
int           lastIndexOf(Object object)
ListIterator<E>     listIterator(int location)
boolean       offer(E o)
boolean       offerFirst(E e)
boolean       offerLast(E e)
E             peek()
E             peekFirst()
E             peekLast()
E             poll()
E             pollFirst()
E             pollLast()
E             pop()
void          push(E e)
E             remove()
E             remove(int location)
boolean       remove(Object object)
E             removeFirst()
boolean       removeFirstOccurrence(Object o)
E             removeLast()
boolean       removeLastOccurrence(Object o)
E             set(int location, E object)
int           size()
<T> T[]       toArray(T[] contents)
Object[]     toArray()

三、set

猜你喜欢

转载自www.cnblogs.com/lbrs/p/10057862.html