Tag: Java

Collections, what to use?

Collection interface has many implementations, like ArrayList, LinkedList, TreeSet and others. With so many variations, some times you don’t known what to use, this depends of your objective. Now I’ll try to explain some differences in ArrayList, LinkedList and TreeSet.

ArrayList
The ArrayList Collection allow to store objects and null values, but your access is unordered, the first object inserted, can be a last to retrieve.

LinkedList
This implementation of Collection is like ArrayList, but the difference is in access to objects stored, where each object is returned in your inserted order.

TreeSet
If you want retrieve the objects of your Collection in specified order, this Collection can do the work! Insert values in TreeSet is equal previously classes, but your return depends of Comparable implemented in values. It sort your object values using result of compareTo method, inherited of Comparable Interface.

For more information, visits Collection Javadoc.


Learn JavaFX in 15 minutes

This video show some commands for JavaFX, from a simple “Hello World” to functions and access modifiers.

Thanks for Roberto Furutani!

Enjoy!


Retrieving hard drives or removable devices

You’ve tried retrieve the hard drives or removable devices using java.io.File and passed “/” like parameter in class constructor? The result is the root of classpath, isn’t?

To obtain the hard drives or removable devices, use File.listRoots(). This code return a File array, where each index of array is a removable device or hard disk unit.

Follow this sample:

File[] units = File.listRoots();

for(File unit : units){
    System.out.println(unit.getAbsolutePath());
}

  • AdSense

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress