WEB开发网      濠电姷鏁告繛鈧繛浣冲洤纾瑰┑鐘宠壘閻ょ偓銇勯幇鍫曟闁稿鍠愰妵鍕冀閵娧佲偓鎺楁⒒閸曨偄顏柡宀嬬畱铻e〒姘煎灡绗戦梻浣筋嚙濮橈箓顢氳濠€浣糕攽閻樿宸ュΔ鐘叉啞缁傚秹宕滆绾惧ジ寮堕崼娑樺缂佹宀搁弻鐔风暋閻楀牆娈楅梺璇″枓閺呯姴鐣疯ぐ鎺濇晝闁靛牆妫欓蹇旂節閻㈤潧浠﹂柛銊ョ埣楠炴劙骞橀鑲╋紱闂佽宕樼粔顔裤亹閹烘挸浜归梺缁樺灦閿曗晛螞閸曨垱鈷戦柟鑲╁仜婵″ジ鎮楀☉鎺撴珖缂侇喖顑呴鍏煎緞濡粯娅囬梻浣瑰缁诲倿寮绘繝鍥ㄦ櫇闁稿本绋撻崢鐢告煟鎼淬垻鈯曢柨姘舵煟韫囥儳绋荤紒缁樼箖缁绘繈宕橀妸褌绱濋梻浣筋嚃閸ㄤ即宕弶鎴犳殾闁绘梻鈷堥弫鍌炴煕閳锯偓閺呮瑧妲愬Ο琛℃斀闁绘劕妯婇崵鐔封攽椤旇棄鍔ら摶鐐烘煕閺囥劌澧柛娆忕箻閺屽秹宕崟顒€娅g紓浣插亾濠㈣泛顑囩粻楣冩煙鐎涙ḿ绠橀柨娑樼У椤ㄣ儵鎮欓鍕紙闂佽鍠栫紞濠傜暦閹偊妲诲┑鈩冨絻椤兘寮诲☉銏犖╅柕澶堝労閸斿绱撴担绋库偓鍝ョ矓瑜版帒鏋侀柟鍓х帛閺呮悂鏌ㄩ悤鍌涘 ---闂傚倸鍊烽悞锔锯偓绗涘厾娲煛閸涱厾顔嗛梺璺ㄥ櫐閹凤拷
开发学院WEB开发Jsp Java写的查找重复电话号码程序 阅读

Java写的查找重复电话号码程序

 2008-01-05 18:59:37 来源:WEB开发网 闂傚倸鍊风欢姘缚瑜嶈灋闁圭虎鍠栫粻顖炴煥閻曞倹瀚�闂傚倸鍊风粈渚€骞夐敓鐘插瀭闁汇垹鐏氬畷鏌ユ煙閹殿喖顣奸柛搴$У閵囧嫰骞掗幋婵冨亾閻㈢ǹ纾婚柟鐐灱濡插牊绻涢崱妤冃℃繛宀婁簽缁辨捇宕掑鎵佹瀸闂佺懓鍤栭幏锟�濠电姷鏁告慨顓㈠箯閸愵喖宸濇い鎾寸箘閹规洟姊绘笟鈧ḿ褍煤閵堝悿娲Ω閳轰胶鍔﹀銈嗗笂閼冲爼鍩婇弴銏$厪闁搞儮鏅涙禒褏绱掓潏鈺佷槐闁轰焦鎹囬弫鎾绘晸閿燂拷闂傚倸鍊风欢姘缚瑜嶈灋闁圭虎鍠栫粻顖炴煥閻曞倹瀚�  闂傚倸鍊烽懗鑸电仚缂備胶绮〃鍛村煝瀹ュ鍗抽柕蹇曞У閻庮剟姊虹紒妯哄妞ゆ劗鍘ч埥澶娢熼柨瀣偓濠氭⒑瑜版帒浜伴柛鎾寸☉閳绘柨顫濋懜纰樻嫼闂佸憡绋戦オ鏉戔枔閺冣偓缁绘稓浠﹂崒姘瀳闂佸磭绮幑鍥嵁鐎n亖鏀介柟閭﹀墯椤斿倹淇婇悙顏勨偓鏍ь潖婵犳艾鍌ㄧ憸蹇涘箟閹绢喗鏅搁柨鐕傛嫹
核心提示:开发工具:Netbeans 4.1 说明: 此程序大体流程 1,打开一个含有多个重复记录的电话号码的文件,Java写的查找重复电话号码程序, 2,系统按行读取文件并添加到向量vectors中,则添加到数组二,否则跳过,注重此时将电话号码转为LONG型, 3

开发工具: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);

jScrollPane1.setViewportView(jTextArea1);

jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

jTextArea2.setColumns(35);

jTextArea2.setRows(5);

jScrollPane2.setViewportView(jTextArea2);

jPanel1.add(jScrollPane2, java.awt.BorderLayout.SOUTH);

jPanel1.setBounds(0, 0, 400, 280);

desktopPane.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

getContentPane().add(desktopPane, java.awt.BorderLayout.CENTER);

fileMenu.setText("文件");

fileMenu.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

fileMenuActionPerformed(evt);

}

});

openMenuItem.setText("打开");

openMenuItem.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

openMenuItemActionPerformed(evt);

}

});

fileMenu.add(openMenuItem);

saveMenuItem.setText("保存");

saveMenuItem.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

saveMenuItemActionPerformed(evt);

}

});

fileMenu.add(saveMenuItem);

//saveAsMenuItem.setText("Save As ...");

//fileMenu.add(saveAsMenuItem);

exitMenuItem.setText("Exit");

exitMenuItem.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

exitMenuItemActionPerformed(evt);

}

});

fileMenu.add(exitMenuItem);

menuBar.add(fileMenu);

editMenu.setText("Edit");

cutMenuItem.setText("Cut");

editMenu.add(cutMenuItem);

copyMenuItem.setText("Copy");

editMenu.add(copyMenuItem);

pasteMenuItem.setText("Paste");

editMenu.add(pasteMenuItem);

deleteMenuItem.setText("Delete");

editMenu.add(deleteMenuItem);

menuBar.add(editMenu);

helpMenu.setText("Help");

contentMenuItem.setText("Contents");

helpMenu.add(contentMenuItem);

aboutMenuItem.setText("About");

aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

aboutMenuItemActionPerformed(evt);

}

});

helpMenu.add(aboutMenuItem);

menuBar.add(helpMenu);

setJMenuBar(menuBar);

pack();

}

// //GEN-END:initComponents

private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed

// TODO 将在此处添加您的处理代码:

JOptionPane.showMessageDialog(null,"Find Phone Num by repeated.","关于",JOptionPane.WARNING_MESSAGE);

}//GEN-LAST:event_aboutMenuItemActionPerformed

private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed

String strFileOpen="";

String lineStr=null;

String returnStr=null;

StringBuffer sbf=new StringBuffer();

StringBuffer bf2=new StringBuffer();

Long[] intArr=null;

//jFileChooser1 =new JFileChooser();

try{

if(this.jFileChooser1.APPROVE_OPTION==this.jFileChooser1.showOpenDialog(this)){

strFileOpen=this.jFileChooser1.getSelectedFile().getPath();

this.setTitle(strFileOpen);

try{

File files=new File(strFileOpen.toString());

vectors.removeAllElements();

InputStreamReader read =new InputStreamReader(new FileInputStream(files),"gb2312");

//BufferedReader br=new BufferedReader(new FileReader(filepath.toString()));

BufferedReader br=new BufferedReader(read);

while((lineStr=br.readLine())!=null){

//returnStr=returnStr+line+"\n\r";

//line=br.readLine();

//处理字符并添加到向量中

vectors.add(new Long(lineStr));

//sbf.append("\n\r");

}

intArr=new Long[vectors.size()];

resultArr=new Long[vectors.size()];

vectors.copyInto(intArr);

Arrays.sort(intArr);

int startIndex=1;

resultArr[0]=intArr[0];

//System.out.println(resultArr[0]+":"+intArr[0]);

for(int j=1;j

//System.out.println(resultArr[startIndex-1]+":"+intArr[j]);

if(resultArr[startIndex-1].compareTo(intArr[j])==0){

bf2.append(intArr[j]+"\n\r");

}

else{

sbf.append(intArr[j]+"\n\r");

resultArr[startIndex]=intArr[j];

startIndex++;

}

//startIndex++;

}

jTextArea1.setText("处理后的结果为:\n\r"+sbf.toString());

jTextArea2.setText("重复的电话号码有:\n\r"+bf2.toString());

}

catch(IOException e){

System.out.println("file open error"+e.getMessage());

}

//this.statubar.setText("Open File:"+this.filename);

}

else

{

return ;

}

}

catch(Exception e){

//this.statubar.setText("Error Open:"+e.getMessage());

}

}//GEN-LAST:event_openMenuItemActionPerformed

private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed

File fileName=null;

String strFileOpen=null;

PrintWriter output=null;

try{

if(this.jFileChooser1.APPROVE_OPTION==this.jFileChooser1.showSaveDialog(this)){

strFileOpen=this.jFileChooser1.getSelectedFile().getPath();

this.setTitle(strFileOpen);

fileName = jFileChooser1.getSelectedFile();

this.setTitle("保存至:"+fileName.getName());

try{

output = new PrintWriter(fileName);

for(int i=0;i

if(resultArr[i]!=null){

output.write(resultArr[i]+"\r\n");

}

}

jTextArea1.setText("成功保存至:\n\r"+strFileOpen);

}

catch(IOException e){

}

finally{

output.close();

output = null;

}

}

}

catch(Exception e){

}

}

photoshop入门教程 Photoshop实例教程 Photoshop cs教程 滤镜 鼠绘 Photoshop照片处理 Photoshop视频教程 Photoshop作品展示 特效 抠图

//GEN-LAST:event_openMenuItemActionPerformed

private void fileMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileMenuActionPerformed

// TODO 将在此处添加您的处理代码:

}//GEN-LAST:event_fileMenuActionPerformed

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed

System.exit(0);

}//GEN-LAST:event_exitMenuItemActionPerformed

//交换位置

private void swap(int loc1, int loc2){

Object tmp = vectors.elementAt(loc1);

vectors.setElementAt(vectors.elementAt(loc2),loc1);

vectors.setElementAt(tmp,loc2);

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Main().setVisible(true);

}

});

}

private javax.swing.JFileChooser jFileChooser1;

// 变量声明 - 不进行修改//GEN-BEGIN:variables

protected javax.swing.JMenuItem aboutMenuItem;

protected javax.swing.JMenuItem contentMenuItem;

protected javax.swing.JMenuItem copyMenuItem;

protected javax.swing.JMenuItem cutMenuItem;

protected javax.swing.JMenuItem deleteMenuItem;

protected javax.swing.JDesktopPane desktopPane;

protected javax.swing.JMenu editMenu;

protected javax.swing.JMenuItem exitMenuItem;

protected javax.swing.JMenu fileMenu;

protected javax.swing.JMenu helpMenu;

protected javax.swing.JPanel jPanel1;

protected javax.swing.JScrollPane jScrollPane1;

protected javax.swing.JScrollPane jScrollPane2;

protected javax.swing.JTextArea jTextArea1;

protected javax.swing.JTextArea jTextArea2;

protected javax.swing.JMenuBar menuBar;

protected javax.swing.JMenuItem openMenuItem;

protected javax.swing.JMenuItem pasteMenuItem;

protected javax.swing.JMenuItem saveAsMenuItem;

protected javax.swing.JMenuItem saveMenuItem;

// 变量声明结束//GEN-END:variables

}

Photoshop入门教程 Photoshop实例教程 Photoshop cs教程 滤镜 鼠绘 Photoshop照片处理 Photoshop视频教程 Photoshop作品展示 特效 抠图

附图:

Java写的查找重复电话号码程序(图一)


Tags:Java 查找 重复

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接