Java Software: 1-Line Sort & Uniq Utility Javaソフトウェア: 1 -ラインの並べ替え& uniqユーティリティ
I had to sort and uniq (create a unique set of strings) a large list with lots of duplicate.私はuniqを並べ替えたり(文字列を作成するユニークな設定の)多くの大規模なリストを重複しています。 My options were to write it in Java or download cygwin and run: cat file | sort | uniq > resultを書くことが私のオプションがcygwinのJavaまたはダウンロードし、実行: catファイル|並び替え| uniq >結果
Cygwin download never works for me. cygwinのダウンロード決して作品です。 After I spend lots of time selecting a juicy list of utilities, it always fails somewhere in the download process.した後、多くの時間を過ごすのリストをジューシーなユーティリティを選択すると、それをダウンロードプロセスのどこかでいつも失敗します。 I liked it much better when it was a single download.私がずっと好き良いときには、 1つのダウンロードしてください。
I opted for Java route naturally.私受け取らないように設定for Javaのルート当然です。 After all it was just a single line of code really.後にすべてのことは、実際のコードの行を1つだけです。
for(String item:getFileAsSet(args[0])) System.out.println(item); を(文字列アイテム: getfileasset ( args [ 0 ] ) ) system.out.println (アイテム) ;
Obviously you are wondering where the heck do I get getFileAsSet .明らかにあなたがどこに行くのヘックgetfileassetやって行くのです。 It is just one of the many reusable java utilities I created to make my job easier.これは再利用できるだけ多くのJavaのいずれかのユーティリティを作る私の仕事を作成が容易になります。 The crucial part of the code for this utility is:の重要な部分のコードをこのユーティリティは:
TreeSet treesetset = new TreeSetセット=新しいtreeset (); while((temp = reader.readLine()) != null) { temp = temp.trim(); // Hate spaces; Your mileage may vary if(temp.length() > 0) { set.add(temp); } } ( ) ;ながら( (気温= reader.readline ( ) ) ! = nullが) (気温= temp.trim ( ) ; / /憎しみスペース;している場合走行距離は異なる場合があります( temp.length ( ) > 0 ) ( set.add (気温) ; ) )
The beauty of this code is that TreeSet is a SortedSet implementation.の美しさは、次のコードは、 treesetは、 sortedset実装します。 Adding to the Set automatically ensures elimination of duplicates as well as sorting.の設定を自動的に追加するだけでなく、重複の排除によりソートします。 All I had to do was just print the result.私はこれを行うにはすべての結果だけを印刷します。
Filed under提出されて Headline Newsニュースの見出し , 、 How Toどのように , 、 Java Software Javaソフトウェア , 、 Tech Note技術のノート | |
| |
RSS 2.0 RSS 2.0を | |
Trackbackトラックバック this Article |この記事|
Email this Article電子メールこの記事
You may also like to readを読むようにすることも可能 |




February 14th, 2007 at 8:23 am 2007年2月14日8:23アム
برنامج source او خوارزمية حساب الميراث في الاسلام برنامجソースاو خوارزمية حساب الميراث في الاسلام