General Java Questions IV
(myfile.properties)
6) When you re done, erase the original and rename your new one to original.zip.
I believe that this may be the only way to do this, since there doesn t seem to be any
random access in the ZIP file.
Kevin T. Smith
Q: About the order of my elements in hastable...
I save some data into hashtable.
For example,
hashtable.put ( "1", "one" );
hashtable.put ( "2", "two" );
hashtable.put ("3" , "three" );
when I get back the element from hashtable using Enumeration class ,
Enumeraton e = hashtable.keys();
while ( e.hasMoreElements() ){
Object k = e.nextElement();
Object v = hashtable.get (k );
}
the default result is
"3","three"
"2", "two"
"1", "one"
here I want to get the data sorted as ascending. ( the order as I insert ) such as
"1", "one"
"2", "two"
"3", "three"
or is it possible to get the data from end of hashtable?
Answer: When you insert elements into a Hashtable, they will not be stored in the
order you insert them. They are stored in a way that makes it easy to find them by
the key you specify.
So, you must either use another data structure (e.g. Vector) or sort them after you
retrieve them from the Hashtable (e.g. by using java.util.Collections, java.util.Arrays).
Marco Schmidt
Q: What is better to use: array or vector?
Just wondering as I am using Vectors to store large amounts of objects from 50 to
4000 and each one has to be "looked at" every time paint is called...
Just wondering if it would be better to use an array, list etc?
Answer 1: Since the Vector method uses an array for storage but has extra steps
involved in getting an element, use an array for fastest access.
WBB Java Cert mock exams http://www.lanw.com/java/javacert/
file:///F|/a_jsite/350_tips/general_java IV.htm (2 of 10) [2001 07 08 11:24:54]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved