27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

General <strong>Java</strong> Questions IV<br />

(myfile.properties)<br />

6) When you're done, erase the original and rename your new one to original.zip.<br />

I believe that this may be the only way to do this, since there doesn't seem to be any<br />

random access in the ZIP file.<br />

--<br />

Kevin T. Smith<br />

Q: About the order of my elements in hastable...<br />

I save some data into hashtable.<br />

For example,<br />

hashtable.put ( "1", "one" );<br />

hashtable.put ( "2", "two" );<br />

hashtable.put ("3" , "three" );<br />

when I get back the element from hashtable using Enumeration class ,<br />

Enumeraton e = hashtable.keys();<br />

while ( e.hasMoreElements() ){<br />

Object k = e.nextElement();<br />

Object v = hashtable.get (k );<br />

}<br />

the default result is<br />

"3","three"<br />

"2", "two"<br />

"1", "one"<br />

here I want to get the data sorted as ascending. ( the order as I insert ) such as<br />

"1", "one"<br />

"2", "two"<br />

"3", "three"<br />

or is it possible to get the data from end of hashtable?<br />

Answer: When you insert elements into a Hashtable, they will not be stored in the<br />

order you insert them. They are stored in a way that makes it easy to find them by<br />

the key you specify.<br />

So, you must either use another data structure (e.g. Vector) or sort them after you<br />

retrieve them from the Hashtable (e.g. by using java.util.Collections, java.util.Arrays).<br />

--<br />

Marco Schmidt<br />

Q: What is better to use: array or vector?<br />

Just wondering as I am using Vectors to store large amounts of objects from 50 to<br />

4000 and each one has to be "looked at" every time paint is called...<br />

Just wondering if it would be better to use an array, list etc?<br />

Answer 1: Since the Vector method uses an array for storage but has extra steps<br />

involved in getting an element, use an array for fastest access.<br />

--<br />

WBB <strong>Java</strong> Cert mock exams http://www.lanw.com/java/javacert/<br />

file:///F|/350_t/350_tips/general_java-IV.htm (2 of 10) [2002-02-27 21:18:34]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!