title: How can I check if an input is a integer or String, etc.. in JAVA?
body: <p>I am wondering how I can check if a user's input is a certain primitive type (I mean integer, String, etc... I think it's called primitive type?). I want a user to input something, then I check if it's a String or not, and do a certain action accordingly. (JAVA)
  I have seen some codes like this:</p>
  
  <pre><code>if (input == (String)input) { (RANDOM STUFF HERE) }
  </code></pre>
  
  <p>or something like </p>
  
  <pre><code>if input.equals((String) input)
  </code></pre>
  
  <p>And they don't work. I want to know how I can <b>Check for only a String?</b> (EDITED OUT)
  I was wondering if there was a function that can do that? Thanks for the answers</p>
  
  <p>EDIT: With the help of everyone I have created my fixed code that does what I want it to:</p>
  
  <pre><code>package files;
  import java.util.*;
  public class CheckforSomething {
  static Scanner inputofUser = new Scanner(System.in);    
  static Object userInput;
  static Object classofInput;
  public static void main(String[] args){
      try{
      System.out.print("Enter an integer, only an integer: ");
      userInput = inputofUser.nextInt();
  
      classofInput = userInput.getClass();
      System.out.println(classofInput);
      } catch(InputMismatchException e) {
          System.out.println("Not an integer, crashing down");
  
      }
  
   }
  
  
  
   }
  </code></pre>
  
  <p>No need for answers anymore, thanks!</p>