Preskočiť na hlavný obsah

Príspevky

Zobrazujú sa príspevky so štítkom tips

When and where to use CharSequence?

CharSequence is cool interface to cover all character/string (buffer/bulder) operation, especially for cases where you want to use String parameters in the methods that are working with texts. Known Java implementing classes are CharBuffer, Segment, String, StringBuffer, StringBuilder. So whenever you are planning some new API, use the CharSequense.

How to convert aray to list and list back to array?

Working with collections, sometimes you need to get an actual array that contains the list. Sometimes in Java array should be converted to List. Check it out how to... This example code converts an array to a list: List listOfStrings = Arrays.asList(arrayOfStrings); On the fly list construction: List listOfStrings = Arrays.asList(new String[]{s1, s2}); And how to convert a list into an array: String[] arrayOfStrings = listOfStrings.toArray(new String[]{}); or String[] arrayOfStrings = listOfStrings.toArray(new String[0]);

How to use Java Jar Tool?

If you need to package your classes in a jar file use jar command line utility. Creted Jar file can be used in class path. creates new JAR: jar cf target.jar inputfiles: It is used to to view all the files of the JAR: jar tf somefile.jar to run a JAR if the manifest file is present in the JAR. The manifest file must contain the information of the class file having main method: java -jar app.jar to extract the JAR: jar xf somefile.jar