6.3 String ? StringBuffer ? - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

6.3 String ? StringBuffer ?

Description:

Title: PowerPoint Author: 1 Last modified by: mdf Created Date: 8/26/2002 10:37:45 AM Document presentation format: Company – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 42
Provided by: 1536
Category:

less

Transcript and Presenter's Notes

Title: 6.3 String ? StringBuffer ?


1
??? ????????
  • 6.1 ?????
  • 6.2 ???
  • 6.3 String ? StringBuffer ?
  • 6.4 ??????
  • 6.5 ?????
  • 6.6 ?????
  • 6.7 Math ?

2
6.1 ?????
??? ????????
  • public class Echo
  • public static void main (String args)
  • for (int i 0 i lt args.length i)
  • System.out.println(argsi)
  • ??
  • java Echo Drink Hot Java
  • Drink
  • Hot
  • Java

??
??
java Echo Drink Hot Java Drink Hot Java
3
6.1 ?????
??? ????????
  • ??
  • ??????????,??????????????
  • ??
  • int firstArg
  • if (args.length gt 0)
  • firstArg Integer.parseInt(args0)

4
6.2 ???
??? ????????
  • ?????????????java.lang????????????,????????,??????
    ???

5
6.2 ???
??? ????????
  • ?????????????java.lang????????????,????????,??????
    ???
  • ??
  • int pInt 500
  • Integer i1 new Integer( pInt)
  • int p2 i1. parseInt()

6
6.3 String ? StringBuffer ?
??? ????????
  • ??
  • String ??????
  • SrtingBuffer ????????
  • 2. ??String ? StringBuffer
  • String "Gobbledy ." new
    String("Gobbledy ")
  • StringBuffer StringBuffer()
  • StringBuffer( int capacity)
  • StringBuffer( String
    initialString)

7
6.3 String ? StringBuffer ?
??? ????????
  • 3. String? StringBuffer??????
  • String charAt ,length, indexOf , lastIndexOf,
    substring , toLowerCase , toUpperCase ,equals
    , equalsIgnoreCase ??
  • StringBufferappend , insert , reverse ,
    setCharAt , setLength
  • ???example63String.txt

8
6.3 String ? StringBuffer ?
??? ????????
  • ?????????
  • ?????
  • toString ???????Character, Integer, Double?
  • valueOf ??String.valueOf()
  • System.out.println(String.valueOf(Math.PI))

9
6.3 String ? StringBuffer ?
??? ????????
  • ?????????
  • ?????(Integer, Double, Float, and
    Long)?valueOf()???????
  • ??
  • String piStr "3.14159"
  • Float pi Float.valueOf(piStr)

10
6.3 String ? StringBuffer ?
??? ????????
  • 6. ????java ???
  • ??????????????,java???????String and
    StringBuffer?
  • ??
  • "Hello World!"
  • int len Goodbye Cruel World.length()
  • String s "Hola Mundo"
  • String cat "cat" System.out.println("con"
    cat "enation")
  • System.out.println("Java's Number " 1)

11
6.4 ??????
??? ????????
  1. System?
  2. ??????(I/O)?
  3. ????

12
6.4 ??????
??? ????????
  • System?
  • System?????????????????System???????,?????????????
    ????
  • ??
  • class UserNameTest
  • public static void main(String args)
  • String name
  • name System.getProperty("user.name")
  • System.out.println(name)

13
6.4 ??????
??? ????????
  • ??????(I/O)?
  • System.in ????
  • System.out ????
  • System.err ??????
  • Standard Output ? Error Streams ???????
  • print, println, and write
  • ??
  • System.out.print("Duke is not a penguin!\n")
  • ???System.out.println("Duke is not a penguin!")

14
6.4 ??????
??? ????????
  • ??????(I/O)?
  • print and println ???
  • Object, String, char, int, long, float,
    double, and boolean.
  • println()?????,?????
  • ???DataTypePrintTest.java

15
6.4 ??????
??? ????????
  • 3. ????
  • ?????????????????????key/value ????
  • java.vm.version 1.2.2
  • path.separator
  • file.separator /
  • user.home /home/basham
  • java.specification.vendor Sun Microsystems Inc.
  • user.language en
  • user.name basham

16
6.4 ??????
??? ????????
  • 3. ????
  • ?????
  • System. getProperties????Properties??
  • System. getProperty?????????
  • ??
  • Properties props System.getProperties()
  • System.getProperty("path.separator")

17
6.5 ?????
??? ????????
  • The Collections API
  • ??collection?????,??????object???
  • The Collection API ???3??? ,??object???
  • Collection ?? objects ,???????,???????
  • ?List(??)????????????,???????
  • ??Set(?)???????,????????????

18
6.5 ?????
??? ????????
19
6.5 ?????
??? ????????
  • ???
  • setExmple.java
  • ListExmple.java

20
6.5 ?????
??? ????????
  • Map
  • Map(??) ???-?????(?),?????????????
  • HashMap?????????(????Hashtable)????-????????,???
    ??????????

21
6.5 ?????
??? ????????
22
6.5 ?????
??? ????????
  • ???
  • PrintingContainers.java
  • ??containers??List, ??Set or Map
  • ???
  • FillingLists.java

23
6.5 ?????
??? ????????
  • Container ??
  • ???????
  • ?????????
  • ???Cat.java
  • Dog.java
  • CatsAndDogs.java

24
6.5 ?????
??? ????????
  • Iterators???
  • ????????????????
  • An Iterator of a Set ?????
  • ListIterator of a List ???????

25
6.5 ?????
??? ????????
26
6.5 ?????
??? ????????
  • Iterators???
  • ???CatsAndDogs2.java
  • ???????
  • HamsterMaze.java
  • ?Iterators????Collection ?????Collection1.java

27
6.5 ?????
??? ????????
  • ??List, LinkedList, ArrayList
  • List(??) ???List??????
  • ????????????
  • List?Collection???????
  • ?List?????????
  • (ListIterator(?????),?????????????????,???????????
    ?????

28
6.5 ?????
??? ????????
  • ??List, LinkedList, ArrayList
  • ArrayList ??????????,???????????????,????????????
    ?ListIterator???ArrayList?????????,???????????
  • LinkedList??????????????????????????????,???.
    ???addFirst(),addLast(),getFirst(),getLast(),remov
    eFirst()??removeLast()(?????????????),????????????
    ???????????

29
6.5 ?????
??? ????????
  • ?LinkedList????(queue)???
  • ???Queue.java
  • Map????
  • Map1.java

30
6.6 ?????
??? ????????
  • .??Arrays?????????????????????sort()?binarySearch
    (),??????String?Object?
  • ???Array1.java

31
6.6 ?????
??? ????????
  • . ?????????????????????(List)???????????????????C
    ollections?,sort(List)????????Comparable?????????
    binarySearch(List,Object)

32
6.5 ?????
??? ????????
  • ??
  • ?????????????????????????????????????????????,????
    ??
  • Colloction????????,?Map???????
  • List????????????,???????????,????????????
  • ArrayList?????????LinkedList??????????????
  • LinkedList ?????????
  • Map ??????object-object?HashMap???????

33
6.5 ?????
??? ????????
  • ??
  • Set ?????????HashSet?????????

34
6.5 Enumeration ??
??? ????????
  • Enumeration ??????????????????
  • nextElement()???????
  • hasMoreElements()??????????????
  • ??
  • Enumeration ??????????????

35
6.6 Vector ?
??? ????????
  • Vector ??????????????????????????
  • ??????????????Vector?????????????
  • ???example66Vector.txt

36
6.7 ?? Stack
??? ????????
  • Stack????Vector?,???Vector?????????????????
  • ??Stack? new Stack()
  • ????
  • Object push(Object o)
  • Object pop()
  • Object peek()
  • boolean empty()
  • int search(Object o)
  • ???example67Stack.txt

37
6.8 ??? Hashtable
??? ????????
  • ????????????????(key/element)?????????????????????
    ??
  • ????????
  • put(Object key, Object value)
  • get(Object key)
  • remove(Object Key)
  • elements()
  • keys()
  • size()
  • isEmpty()
  • ??? example68HashApp.txt

38
6.8 ??? Hashtable
??? ????????
  • ?????????????????????????????????????
  • ???example68Hashtable.txt

39
6.9 StringTokenizer ?
??? ????????
  • StringTokenizer ?????String???????????????????????
    ??????????Enumeration???
  • ????????
  • hasMoreTokens()
  • nextToken()
  • countTokens()
  • nextElement()
  • hasMoreElements()
  • ???example69Token.txt

40
6.10 Math ?
??? ????????
  • Math?????????????,???????????????????
  • ??
  • public class MathApp
  • public static void main(String args)
  • System.out.println(Math.E)
  • System.out.println(Math.PI)
  • System.out.println(Math.abs(-1))
  • System.out.println(Math.max(3,5))
  • for(int i0ilt5i)
  • System.out.print(Math.random()" ")
  • System.out.println()

41
  • ???????.txt
Write a Comment
User Comments (0)
About PowerShow.com