在堆栈中,push为入栈操作,pop为出栈操作

LinkedList提供以下方法:(ArrayList无此类方法)

addFirst();   

removeFirst();

 addLast();

 removeLast();

在堆栈中,push为入栈操作,pop为出栈操作。

 

Push用addFirst();pop用removeFirst(),实现后进先出。

用isEmpty()--其父类的方法,来判断栈是否为空。

 

在队列中,put为入队列操作,get为出队列操作。

Put用addFirst(),get用removeLast()实现队列。

 1 package TomTexts;
 2 
 3 public class TomTexts_11 {
 4     public static void main(String[] args)
 5     {
 6     String s1="Javav";
 7     char c=s1.charAt(2);
 8     System.out.println("c="+c);
 9     int i=s1.indexOf('a');
10     System.out.println("fistchar="+i);
11     int j=s1.lastIndexOf('a');
12     System.out.println("lastchar="+j);
13     i= s1.indexOf("av");
14     System.out.println("fiststring="+i);
15     j=s1.lastIndexOf("av");
16     System.out.println("laststring="+j); 
17     }
18 }
原文地址:https://www.cnblogs.com/borter/p/9420345.html