Justifying a string followed by a number I started practicing on HackerRank to see how my learning is going on with Java. 
I wrote this code for problem which involved input having:


  
  String with maximum length of 10, followed by
  A 3 digit or lesser integer
  


Examples: "java 100", "Amazing 98"

Expected output:


  
  String should be left-justified with trailing white spaces till 15th character
  Leading digit of integer starts at 16th place with leading zeroes if it is less than 3 digits(padding) to make up for 18 characters
  


Examples: "java           100", "Amazing        098"

package HackerRank;

import java.util.ArrayList;
import java.util.Scanner;

public class IOFormatting {
    public ArrayList&lt;String&gt; getAllLines(){
        ArrayList&lt;String&gt; allInputs = new ArrayList&lt;String&gt;();
        Scanner getIp = new Scanner(System.in);
        while(getIp.hasNext()) {
            allInputs.add(getIp.nextLine());
        }
        getIp.close();
        return allInputs;
    }

    public ArrayList&lt;Character&gt; getTheInputAsArrayList(String input) {
        ArrayList&lt;Character&gt; inputLine = new ArrayList&lt;Character&gt;();
        for(int itr1=0;itr1&lt;input.length();itr1++) {
            inputLine.add(input.charAt(itr1));
        }
        return inputLine;
    }

    public ArrayList&lt;Character&gt; formatTheArrayList(ArrayList&lt;Character&gt; inputLine){
        int itr2 = getBreakPoint(inputLine);
        for(int itr3=itr2+1;itr3&lt;15;itr3++) {
            inputLine.add(itr3,' ');
        }
        return inputLine;
    }

    public int getBreakPoint(ArrayList&lt;Character&gt; inputLine){
        for(int itr2=0;itr2&lt;=10;itr2++) {
            if(inputLine.get(itr2) == ' ') {
                return itr2;
            }
        }
        return 0;
    }

    public ArrayList&lt;Character&gt; doIntegerPadding(ArrayList&lt;Character&gt; inputLine){
        int padSize = 18 - inputLine.size();
        if(padSize&gt;0) {
            for(int itr4=15;itr4&lt;=14+padSize;itr4++) {
                inputLine.add(itr4,'0');
            }
        }
        return inputLine;
    }

    public String convertToFinalString(ArrayList&lt;Character&gt; inputLine) {
        String outputString = "";
        StringBuffer sb = new StringBuffer();
        for (Character s : inputLine) {
             sb.append(s);
        }
        outputString = sb.toString();
        return outputString;
    }

    public static void main(String args[]) {
        IOFormatting io = new IOFormatting();
        ArrayList&lt;String&gt; allInputs = io.getAllLines();
        System.out.println("================================");
        for(int mainItr=0;mainItr&lt;allInputs.size();mainItr++) {
            String input = allInputs.get(mainItr);
            ArrayList&lt;Character&gt; inputLine = io.getTheInputAsArrayList(input);
            inputLine = io.formatTheArrayList(inputLine);
            inputLine = io.doIntegerPadding(inputLine);
            String outputString = io.convertToFinalString(inputLine);
            System.out.println(outputString);
        }
        System.out.println("================================");
    }
}
You are vastly overcomplicating the solution.  The Scanner is perfectly capable of reading a string and an integer separately.  Then, it is a simple matter of calling System.out.printf() with the appropriate width specifications:


%-15s for a string, left-justified, with trailing spaces
%03d for an integer, zero-padded


Also, Scanner is AutoCloseable, so you should use a try-with-resources block instead of calling .close() on it manually.

import java.util.Scanner;

public class IOFormatting {
    public static void main(String[] args) {
        try (Scanner input = new Scanner(System.in)) {
            while (input.hasNext()) {
                System.out.printf("%-15s%03d%n", input.next(), input.nextInt());
            }
        }
    }
}


If you really wanted to do the formatting the hard way by inserting spaces and zeroes, I suggest editing each line using StringBuilder.insert() — your ArrayList&lt;Character&gt; is a rather unnatural way to edit a string.