Explore my IV (θ?θ#) on the road to software engineering

Source: Internet
Author: User

Development Language :Java

Development Tools :UltraEdit

Small Partner Blog: http://www.cnblogs.com/hyating/

GitHub address : https://github.com/JUNYU217/2016-03-08

|| For the end of the month, the net fee owed ... I'm sorry for the long haul. Qaq | |

------Personal Summary------

Through this assignment, I learned the use of the file stream, but also thanked the small partners for their help, gave me the framework of the idea

------Job Requirements------
 基于作业3的结果,读取一个较小的文本文件,统计该文件中的单词的频率,并将统计结果输出到当前目录下的 Result1.txt 文件。 (第一阶段初稿完成该要求)
    • First sort by frequency from high to low
    • Words of the same frequency, sorted in dictionary order
    • Details Stamp This!
------Program Writing------

This role is based on the third job change, the specific method in the code to reflect

First of all thanks to my roommate Miao Center provides me with the sorting algorithm, I have been tangled for a long time, through the key sort, by the value sort has not been up to the sorting requirements

list<map.entry<string, integer>> list = new arraylist<map.entry<string, integer>> ( Map.entryset ()); Collections.sort (list, new comparator<map.entry<string, integer>> () {public     int compare (map.entry <string, integer> O1, map.entry<string, integer> O2) {     if (O1.getvalue () <o2.getvalue ()) return 1; else if (O1.getvalue () >o2.getvalue ()) Return-1;elsereturn (O1.getkey (). CompareTo (O2.getkey ()));}} );

After sorting, the output is completed through the methods provided by IO in Java

File outfile = new file ("D:\\software\\sorfwaretest\\result.txt");         Try         {             if (file.exists ()) Outfile.delete ();            BufferedWriter bw = new BufferedWriter (new FileWriter (outfile));             StringBuffer out = new StringBuffer ();             for (map.entry<string,integer> mapping:list)            {                 out.append (Mapping.getkey () + ":" +mapping.getvalue () + "\ r \ n");             }             Bw.write (Out.tostring ());             Bw.flush ();             Bw.close ();         }         catch (IOException e)         {             e.printstacktrace ();        });

------Program runs------

Before compiling

After compiling and running, Result.txt is generated.

Open Result.txt, the result is correct ~

Explore my IV (θ?θ#) on the road to software engineering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.