Q:

Java - How to print from 0 to z without !@#$%^&*()?><":{}| letters, only alphabet and numbers

I'm trying to get a txt file with only the alphabet and numbers writted.
In the txt file there are also the non alphabet characters.
public class WordChanger2 {

    static int input = 2; /// input line length

    public static ArrayList<Character> str; /// a list containing characters.
    public static PrintWriter output; 
    public void saveToFile(int size,int lineSize){    

        if(size == lineSize){
            String s = "";
            for (Character str1 : str) {
                s+=str1;
            }
            output.println(s);
            return;
        }
        for(char i = '0';i<='z';i++){ //from number 0 to lower z
            str.add(i);
            saveToFile(size+1,lineSize);
            str.remove(str.size()-1);
            System.out.println(str); //showing the Characters on console
        }
    }

    public static void main(String[] args) throws FileNotFoundException {
        int lineSize = input;
        output = new PrintWriter("E:\\output.txt");  /// file path
        str = new ArrayList<Character>();

        WordChanger2 c =  new WordChanger2();
        c.saveToFile(0 ,lineSize);
        output.close();
        System.out.println("Done! check the Txt file on your E: drive");
    }
}

Trying to get this:

00
01
02
03
04
05
06
07
08
09
0A
0B
0C
0D
0E
0F
0G
0H
0I
0J
0K
0L
0M
0N
0O
0P
0Q
0R
0S
0T
0U
0V
0W
0X
0Y
0Z
0a
0b
0c
0d
0e
0f
0g
0h
0i
0j
0k
0l
0m
0n
0o
0p
0q
0r
0s
0t
0u
0v
0w
0x
0y
0z

A:

Solution 1:
Use Character#IsLetterOrDigit(char) method in the forloop
It's quite explicit.
for(char i = '0';i<='z';i++){ //from number 0 to lower z
    if (Character.IsLetterOrDigit(i) {
        str.add(i);
        saveToFile(size+1,lineSize);
        str.remove(str.size()-1);
        System.out.println(str); //showing the Characters on console
    }
}

Solution 2:
Use more loops:
for(char i = '0';i<='9';i++){ //from number 0 to 9
    //do something
}
for(char i = 'A';i<='Z';i++){ //from letter A to Z
    //do something
}
for(char i = 'a';i<='z';i++){ //from letter a to z
    //do something
}

This could be improved to avoid to much code duplication
Solution 3: (credits for Andy Turner)
Create a String containing each letters and digits in the correct order and loop on this string to build the ouptut
String table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (int i=0; i<table.size(); i++) {
    str.add(table.charAt(i));
    ...
}

Side note:
  I think using recursive call to do what you are trying to is a bit overkill. Why not build a single string, appending characters in the loop and when the loop ends, write it where ever you want?

