title: List of all binary combinations for a number in Java
body: <p>I am working on a project involving "Dynamic Programming" and am struck on this trivial thing, please help.</p>
  
  <p>Suppose I take 4 as an input, I want to display something like: 0000 to 1111</p>
  
  <p>But, if I input 5, I want to display like: 00000 to 11111 and so on.</p>
  
  <p>Thanks in advance,</p>
  
  <p><strong>EDIT</strong>: Please don't post asking me for the code. This is not a homework problem and I don't need any code, just tell me the logic for it and I would be happy.</p>
  
  <p><strong>EDIT2</strong>: WTH is happening with Stackoverflow, did I ask any of you to write code for me? I want the person who downvoted to upvote it. What is a point of this forum if I can't for help?</p>
  
  <p>Share the logic with me. We can discuss and I do not require the code for this.</p>
  
  <p><strong>EDIT3</strong>: Here I am posting the code which I tried. I hope this "SATISFIES" all the people who were thinking I have not tried anything.</p>
  
  <pre><code>import java.util.ArrayList;
  </code></pre>
  
  <p>public class RegularInvestigator {</p>
  
  <p>public ArrayList createCombinations(ArrayList listOfFlightNumbers) {</p>
  
  <pre><code>ArrayList&lt;String&gt; result = new ArrayList&lt;String&gt;();
  
  for(int i = 1; i &lt; listOfFlightNumbers.size(); i++) {
  
    String binaryEqvivalent = Integer.toBinaryString(i);System.out.println(binaryEqvivalent);
    String element = "";
  
    for(int j = 0; j &lt; binaryEqvivalent.length(); j++)
      if(binaryEqvivalent.charAt(j) == '1')
        element += listOfFlightNumbers + " ";
  
    result.add(element.substring(0, element.length() - 1));
  }
  
  return result;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>private String getContent(ArrayList&lt;String&gt; flight) {
  String temp = "";
  
  for(int i = 0; i &lt; flight.size() - 1; i++)  temp += flight.get(i) + " ";
  
  temp += flight.get(flight.size() - 1);
  
  return temp;
  </code></pre>
  
  <p>}</p>
  
  <p>private ArrayList removeElementAtIndex(ArrayList flight, int position) {</p>
  
  <pre><code>ArrayList&lt;String&gt; res = new ArrayList&lt;String&gt;();
  
  for(int i = 0; i &lt; flight.size(); i++) {
    if(i != position) res.add(flight.get(i));
  }
  
  return res;
  </code></pre>
  
  <p>}
  }</p>
  
  <p><strong>EDIT4</strong>: Thank you phoxis, PengOne, Jerry Coffin and oliholz for your valuable answers :)</p>