从文件中读取并按升序显示不重复的单词. [英] Read from file and display nonduplicate words in ascending order.
本文介绍了从文件中读取并按升序显示不重复的单词.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被要求编写一个程序以从文本文件读取并以升序显示不重复的单词.文本文件作为命令行参数传递.基本上,我设法编写了一个程序来读取预定义的String并显示所有非重复项.剩下要做的就是从文件中读取.这是我无法理解的.非常感谢.这是我的代码:
I am asked to write a program to read from a text file and display nonduplicate words in ascending order. The text file is passed as a command-line argument. Basically, I''ve managed to write a program to read a predefined String and display all nonduplicates. All is left to do is to read from a file. This is something I am not able to comprehend. Thanks a lot. Here is my code:
import java.util.*;
public class NonduplicateWords {
public static void main(String[] args) {
String text = "Testing. I have a testing text. Have a great day";
TreeSet<String> set = new TreeSet<String>();
String[] words = text.split("[ \n\t\r.,;:!?(){}]");
for (int i = 0; i < words.length; i++) {
String value = words[i].toLowerCase();
if (words[i].length() > 0)
set.add(value);
}
for (Object element: set)
System.out.println(element.toString() + " ");
}
}
推荐答案
您尝试过Google吗? http://www.javapractices.com/topic/TopicAction.do?Id=42
Did you try Google? http://www.javapractices.com/topic/TopicAction.do?Id=42
尝试 Java教程 [
Try the Java Tutorials[^]; there are samples of just about everything you need.
这篇关于从文件中读取并按升序显示不重复的单词.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文