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 }