title: Java - Get All Permutations, Substrings and Permutations of every Substring of a String
body: <p>Firstly, I'll start off by saying English is not my first language so I apologize for any poor explanations.</p>
  
  <p>I want to know how to get every single substring of a String with so many different orders. Before you tell me this question has been asked before, I want to say that almost every code implementation of this task I see does not include duplicates. But Say I had a string "enviroment" and I wanted every single substring including "ment", "met", "ten", "net","note", "more" e.t.c e.t.c how would I acheive this??</p>
  
  <p>This is the function I wrote.</p>
  
  <pre><code>     public static ArrayList&lt;String&gt; getAllSubstringsOfAString(String inputString)
       {
       ArrayList&lt;String&gt; allSubstrings = new ArrayList&lt;String&gt;();
       String sub;
       for(int i = 0; i &lt; inputString.length(); i++)
       {
          for (int j = 1; j &lt;= inputString.length() - i; j++)
          {
              sub = inputString.substring(i , i + j);
              allSubstrings.add(sub);
          }
        }
        return allSubstrings;
       }
  </code></pre>
  
  <p>When I run this function</p>
  
  <pre><code>    public static void main(String[] args) throws IOException {
      ArrayList&lt;String&gt; allSubStrings = getAllSubstringsOfAString("environment");
      for (String allSubString : allSubStrings) {
          System.out.println(allSubString);
      }
  </code></pre>
  
  <p>it prints this out</p>
  
  <pre><code>    e
      en
      env
      envi
      envir
      enviro
      environ
      environm
      environme
      environmen
      environment
      n
      nv
      nvi
      nvir
      nviro
      nviron
      nvironm
      nvironme
      nvironmen
      nvironment
      v
      vi
      vir
      viro
      viron
      vironm
      vironme
      vironmen
      vironment
      i
      ir
      iro
      iron
      ironm
      ironme
      ironmen
      ironment
      r
      ro
      ron
      ronm
      ronme
      ronmen
      ronment
      o
      on
      onm
      onme
      onmen
      onment
      n
      nm
      nme
      nmen
      nment
      m
      me
      men
      ment
      e
      en
      ent
      n
      nt
      t
  </code></pre>
  
  <p>Which is only a small part of what I want. I want the function to be able to get substrings in every order. For example, If I wanted it to include Strings like "net", "ten", "never" e.t.c, as they are all substrings of the word "environment".  What changes do I have to make on my function to attain this?</p>
  
  <p>Also, as I am a Java beginner, I would like to know If my code is well written and what changes I can make to my code to make it perform better and look better, and to follow common Java coding conventions.</p>
  
  <p>Thanks in advance</p>