why we have to use index!=1 for alphabets in java : Iam unable to get why we should use idx != -1 in a if statement

here is my friend's code

    public static String encrypt(String input, int key)
            {
                String alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                String shifted =alphabet.substring(key)+alphabet.substring(0,key);
                StringBuilder encrypted=new StringBuilder(input);
                for(int i=0; i<encrypted.length();i++)
                {
                    char current=encrypted.charAt(i);
                    int idx=alphabet.indexOf(current);
                    if(idx !=-1) {
                        char newchar = shifted.charAt(idx);
                        encrypted.setCharAt(i, newchar);
        
                    }
        
                }
                return encrypted.toString();
        
        
            }
please help me 
Thanks.