Posts

Java Program to read Excel File and Load into Array

Image
Excel is one of the most important productivity tools used in offices. It is also a great organizational tool, and its really easy to create tables in excel to store different kinds of data.  When doing automation, excel is an important tool to store data for automation scripts, which makes reading Excel data using Java code an important Interview Question. So, today we'll learn how to read an excel sheet using Java, and return the contents as a String Array. The Array can then be utilized as per your requirement.  We are reading an xlsx file, the most recent and most popular excel format. We need to import the below classes: import java . io . File ; import java . io . FileInputStream ; import org . apache . poi . xssf . usermodel . XSSFCell ; import org . apache . poi . xssf . usermodel . XSSFRow ; import org . apache . poi . xssf . usermodel . XSSFSheet ; import org . apache . poi . xssf . usermodel . XSSFWorkbook ; java.io.File and java.io.FileInputStream will ...

Java Program to Sort Characters of a String

Image
  Sorting a String's characters is one of the most asked Interview Questions in Java. Today let's see how this can be solved in a really easy manner.  We will be utilizing an inbuilt java function in Java.Utils library -> Arrays.sort() We need to import Java.utils in order to use it.  import java . util . * ; A string is nothing but an array of characters. The function that we are going to use also needs an char array as an input. So, we'll be converting the String into a character array.  //Load the string into a character array. char [ ] temp = a . toCharArray ( ) ; Now we'll use the Arrays.sort function to do the heavy work of sorting for us.  //Sort the Array Arrays . sort ( temp ) ;  Let's combine all this information together for a working code.  You can copy paste this code into a new .java file and see it working for yourself! package coding ; import java . util . * ; public class Practice { public static void main ( Stri...