Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Some guesses, related to mr Skeets answer and your apparent confusion...</p> <p>Are you sure you are not inserting the <strong>whole line</strong> in the TreeSet? If you are going to use ONLY the second column, you will need to split() the strings (representing the lines) into columns - that's nothing that's done automatically.</p> <p>Also, If you are actually trying to sort the whole file using the second column as key, You will need a <strong>TreeMap</strong> instead, and use the 2:nd column as key, and the whole line as data. But that won't solve the splitting, it only to keep the relation between the line and the key.</p> <p>Edit: Here is some terminology for you, you might need it.</p> <p>You have a <code>Set</code>. It's a collection of other objects - like <code>String</code>. You <code>add</code> other objects to it, and then you can fetch all objects in it by <code>iterating</code> through the set. Adding is done through the method <code>add()</code>and iterating can be done using the enhanced <code>for loop</code> syntax or using the <code>iterator()</code> method.</p> <p>The set doesn't "grab" or "take" stuff; You <code>add</code> something to the set - in this case a <code>String</code> - Not an array of Strings which is written as <code>String[]</code> </p> <p>(Its apparently possible to add array to a TreeSet (they are objects too) , but the order is not related to the contents of the String. Maybe thats what you are doing.)</p> <pre><code>String key = splittedLine[1]; // 2:nd element </code></pre> <p>"The second element of the keys" doesn't make sense at all. And what's the duplicates you're talking about. (note the correct use of apostrophes... :-)</p>
 

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