General Java Questions II
Increases the capacity of this vector, if necessary, to ensure that it can hold at least
the number of components specified by the minimum capacity argument.
Parameters: 
minCapacity   the desired minimum capacity.
 What re the differences between classpath and import in the java application? 
Do I need to have the package in the classpath first before importing in a java
application or need not?
Answer: Classpath is an environment variable of your OS, you have to set it (or
better: Java sets it) to tell Java where to search for classes. 
You use import in a program to let Java search for the specified classes within the
classpath. This implies that the package must be in the classpath.
  
Stephan Effelsberg
 Q: What is difference between Iterator and Enumeration?
First of all Java FAQ Team wish you !!!HAPPY NEW YEAR!!! and then
Answer: from
http://java.sun.com/docs/books/tutorial/collections/interfaces/collection.html
The object returned by the iterator method deserves special mention. It is an Iterator,
which is very similar to an Enumeration, but differs in two respects: 
Iterator allows the caller to remove elements from the underlying collection during the
iteration with well defined semantics. 
Method names have been improved. 
The first point is important: There was no safe way to remove elements from a
collection while traversing it with an Enumeration. The semantics of this operation
were ill defined, and differed from implementation to implementation. 
The Iterator interface is shown below: 
public interface Iterator {
   boolean hasNext();
   Object next();
   void remove(); // Optional
}
The hasNext method is identical in function to Enumeration.hasMoreElements, and
the next method is identical in function to Enumeration.nextElement. The remove
method removes from the underlying Collection the last element that was returned by
next. The remove method may be called only once per call to next, and throws an
exception if this condition is violated. Note that Iterator.remove is the only safe way to
modify a collection during iteration; the behavior is unspecified if the underlying
collection is modified in any other way while the iteration is in progress. 
The following snippet shows you how to use an Iterator to filter a Collection, that is, to
traverse the collection, removing every element that does not satisfy some condition: 
static void filter(Collection c) {
   for (Iterator i = c.iterator(); i.hasNext(); )
       if (!cond(i.next()))
       i.remove();
}
file:///F|/a_jsite/350_tips/general_java II.htm (10 of 14) [2001 07 08 11:24:53]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved