How to iterate Map in reverse order

Iterating in reverse order means fetching last element of the map first, second last element at second position and so on. Simple logic is to start a loop from last position of the map till its beginning and fetch element at that position but unfortunatelyjava.util.Map interface or any of its implementations does not have a method to retrieve elements based on index hence you cannot fetch an element based on its position. So how can we reverse iterate a map. Read on !!!

(more…)

Continue Reading

How to sort a Map in java 8 / Sort a map using Stream

Sorting values means arranging them in a particular order. The order may be ascending or descending. When the term sorting refers to a Map, it may be sorted on the basis of its keys or values. It depends completely on the requirement.

Java 8 provides a convenient method to sort a map. Using this method will cut down the lines of code used by traditional methods of using java.util.TreeMapor java.util.Comparator to some extent. (more…)

Continue Reading

How to read user input in java / Various ways of reading user input in java / Various ways to read input from keyboard in java

All interactive applications have one thing in common…. Interaction with end user. An application can easily send its output to the user by printing on console (monitor) but how the application will get what user enters, that is sending user input to the program. coDippa will demonstrate different ways to do this. (more…)

Continue Reading

How to convert String to integer in java / Various ways to convert String to integer in java

Why convert String to integer

Suppose you have a web application which takes numeric items such as age, zip code, number of employees etc. as input from the user and store it in a database. In ideal applications, database columns for such type of values would be of integer type and the values received from browser on the server would be in String format. Thus a conversion from String to integer is necessary. There are many ways to convert a String to integer in java.

(more…)

Continue Reading

How to read an excel file in java

Microsoft excel is the most widely used program to maintain data. Hence it becomes vital that the data from an excel sheet be read directly to a java program so that it may be used further to dump into a database or written to an XML file. Java itself does not provide any features to perform excel related operations but there are external libraries written in java which support this. Two of the common libraries are Apache POI and jexcel (or jxl). Both of them provide convenient methods to handle excel files. This post will be using jexcel (or jxl) api for its demonstration. (more…)

Continue Reading

How to write an excel file in java / How to write data to excel in java

Microsoft excel is the most widely used program to maintain data. Hence it becomes vital that the data from a java program be directly written to an excel file in different rows and columns. Java itself does not provide any features to perform excel related operations but there are external libraries written in java which support this. Two of the common libraries are Apache POI and jexcel (or jxl). Both of them provide convenient methods to handle excel files. This post will be using jexcel (or jxl) api for its demonstration.

(more…)

Continue Reading

How to get current date in java / Various ways to get the current date in java

Most applications require calculating current date for different reasons. It may be for logging events, for saving the creation, updation or deletion time of entities, recording the login details of a user and so on. Java provides different methods to calculate current date and time. Following article explains different methods to obtain current date and/or time in java. (more…)

Continue Reading
Close Menu