Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this works:</p> <pre><code>String s = "0B85 61 0B86 6161 0B86 41 0B87 69 0B88" + " 6969 0B88 49 0B89 75 0B8A 7575 0B8F 6565"; String[] parts = s.split(" "); String[][] table = new String[parts.length / 2][2]; for (int i = 0, r = 0; r &lt; table.length; r++) { table[r][0] = parts[i++]; table[r][1] = parts[i++]; } System.out.println(java.util.Arrays.deepToString(table)); // prints "[[0B85, 61], [0B86, 6161], [0B86, 41], [0B87, 69], // [0B88, 6969], [0B88, 49], [0B89, 75], [0B8A, 7575], [0B8F, 6565]] </code></pre> <p>Essentially you <code>split(" ")</code> the long string into parts, then arrange the parts into a 2 column <code>String[][] table</code>.</p> <p>That said, the best solution for this would be to have a <code>Entry</code> class of some sort for each row, and have a <code>List&lt;Entry&gt;</code> instead of a <code>String[][]</code>.</p> <hr> <blockquote> <p><em>NOTE: Was thrown off by formatting, keeping above, but following is what is needed</em></p> </blockquote> <p>If you have <code>columns.txt</code> containing the following:</p> <pre><code> 0B85 61 0B86 6161 0B86 41 0B87 69 0B88 6969 0B88 49 0B89 75 0B8A 7575 0B8F 6565 </code></pre> <p>Then you can use the following to arrange them into 2 columns <code>String[][]</code>:</p> <pre><code>import java.util.*; import java.io.*; //... List&lt;String[]&gt; entries = new ArrayList&lt;String[]&gt;(); Scanner sc = new Scanner(new File("columns.txt")); while (sc.hasNext()) { entries.add(new String[] { sc.next(), sc.next() }); } String[][] table = entries.toArray(new String[0][]); System.out.println(java.util.Arrays.deepToString(table)); </code></pre> <p>I will reiterate that a <code>List&lt;Entry&gt;</code> is much better than a <code>String[][]</code>, though.</p> <h3>See also</h3> <ul> <li><em>Effective Java 2nd Edition, Item 25: Prefer lists to arrays</em></li> <li><em>Effective Java 2nd Edition, Item 50: Avoid strings where other types are more appropriate</em></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload