1.Enumeration interface The enumeration interface uses two methods to retrieve a series of objects or values: Nextelement (): Get Next Object hasMoreElements (): Checks if there are more objects in the sequence Attention: The elements of the enumeration interface can only be accessed once. 2.Vector class The Vector class implements the ability to grow an array. Arrays can be either larger or smaller. Functions: Adding, deleting, and inserting objects, testing the contents of the vector, and retrieving the specified object. See Example: Example66Vector.txt 3. Stack Stacks The stack class extends the vector class and inherits the method of the vector class. It implements the function of last-in-first-out. Create Stack class: New Stack () Common methods: Object push (Object o) Object pop () Object Peek () Boolean empty () int search (Object o) See Example: Example67Stack.txt 4. Hash table Hashtable A hash table can also store an indeterminate number of object pairs (key/element). It can be implemented to put different types of objects into the same hash list. Some of the commonly used methods are: Put (object key, Object value) Get (Object key) Remove (Object Key) Elements () Keys () Size () IsEmpty () See Example: Example68HashApp.txt A hash table enables you to put different types of objects into the same hash table. It is to be combined with a forced type conversion. See Example: Example68Hashtable.txt 5.StringTokenizer class The StringTokenizer class is used to create a syntax parser for a string object. It parses a string based on a set of delimiters. It executes the enumeration interface. Some of the commonly used methods are: Hasmoretokens () NextToken () Counttokens () Nextelement () hasMoreElements () See Example: Example69Token.txt 6.Math class The math class contains a set of static mathematical methods, including: algebra, triangles, exponents, logarithms, random numbers, and so on. Examples: 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 i=0;i<5;i++) System.out.print (Math.random () + ""); System.out.println (); } }
|