开发工具:Netbeans 4.1
说明:
此程序大体流程
1。打开一个含有多个重复记录的电话号码的文件。
2。系统按行读取文件并添加到向量vectors中,注意此时将电话号码转为LONG型。
3。新建一个LONG型数组,大小为vectors.size。并将vectors数据复制到这个数组中。
4。对上面的数组进行排序。
5。新建一个LONG型数组二,大小为vectors.size。
6。循环遍历数组一,并对比是否数组二中已有数据,如没有,则添加到数组二,否则跳过。
测试一万条记录的执行时间为不到2S。
/*
* Main.java
*
* Created on 2006年2月13日, 下午2:07
*/
package phoneutil;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author http://www.tot.name
*/
public class Main extends javax.swing.JFrame {
private Vector vectors=new Vector();
Long[] resultArr=null;
/** Creates new form Main */
public Main() {
initComponents();
this.setSize(405,400);
this.setTitle("电话号码查询");
this.setResizable(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jFileChooser1 =new JFileChooser();
desktopPane = new javax.swing.JDesktopPane();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jTextArea2 = new javax.swing.JTextArea();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem();
saveMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu();
cutMenuItem = new javax.swing.JMenuItem();
copyMenuItem = new javax.swing.JMenuItem();
pasteMenuItem = new javax.swing.JMenuItem();
deleteMenuItem = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
contentMenuItem = new javax.swing.JMenuItem();
aboutMenuItem = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.BorderLayout());
jTextArea1.setColumns(35);
jTextArea1.setRows(15);
jTextArea1.setTabSize(4);