title: Substrings and if statements in Java
body: <p>I'm a pretty new programmer and as part of a few projects I'm doing I'm using substrings. In all of these I've run across a problem with if statements. Say I have two variable, one that is a substring of some other string, and another that should be the equivalent to that first substring. If I try to check if they are equal in an if statement (which they should be) it returns false for and == check. Here's a bit of code to demonstrate.</p>
  
  <pre><code>public class Substringproblem{
  
      static void method(){
  
                  String random="somestring";
  
                  String randomsubstring=random.substring(0,3);
  
                  String should_be_randomsubstring="som";
  
                 if(randomsubstring==should_be_randomsubstring){
                       System.out.println("Success");
                 }else{
                       System.out.println("Failure");
                               System.out.println(randomsubstring);
                 }
                 }
                 public static void main(String[] args) {
                           method();
                 }
  
  }
  </code></pre>
  
  <p>I get the feeling I'm missing something really obvious but I've been looking for a bit and haven't spotted anything that is like this. Help would be really appreciated.</p>