Java HashMap Sepator and Fields -


i want use separtor , different fields in hashmap, trying write program find duplicate firstname , lastname fields in data add sequction number, check firstname && lastname in records if firstname && lastname found duplicate add seqnumber in feilds 0,1,2,3.. if didn't find duplicate 0

i write code working fine.. but, checking line.. instead of fields, need check 2 fields firstname , lastname..

please me!!

here inputdata file:- have data file like:

custmernumber,firstname,lastname,address1,city 123456789,abcd,efgh,12 spring st,atlanta 2345678,xyz,lastname,16 sprint st,atlanta 232345678,abcd,efgh ,1201 sprint st,atlanta  1234678,xyz,lastname,1234 oakbrook pkwy,atlanta 23556,abcd,efgh,3201 sprint st,atlanta 34564,robert,parker,12032 oakbrrok,atlanta 

i want output data file like:

custmernumber,firstname,lastname,address1,city,**seqnumber** 123456789,**abcd,efgh**,12 spring st,atlanta,**0** 232345678,**abcd,efgh** ,1201 sprint st,atlanta,**1**  23556,**abcd,efgh**,3201 sprint st,atlanta,**2** 2345678,**xyz,lastname**,16 sprint st,atlanta,**0** 1234678,**xyz,lastname**,1234 oakbrook pkwy,atlanta,**1** 34564,**robert,parker**,12032 oakbrrok,atlanta,**0** 

here code:

import java.io.file; import java.io.filenotfoundexception; import java.util.hashmap; import java.util.map; import java.util.scanner;   public class test1 {      /**      * @param args      * @throws filenotfoundexception       */     public static void main(string[] args) throws filenotfoundexception {         // todo auto-generated method stub          map<string, integer> names = new hashmap<>();          file dir = new file("data_file_in");          (file file : dir.listfiles()) {             scanner s = new scanner(file);              s.nextline();                 while(s.hasnextline()) {                 string line = s.nextline();                 if(!names.containskey(line)) {                     names.put(line, 0);                 }                 names.put(line, names.get(line) + 1);             }             for(string name : names.keyset()) {                 for(int = 1; <= names.get(name); i++) {                     system.out.println(name + "---->" + (i-1));                 }             }              s.close();          }      }  } 

my code checking line if line duplicate sequction number 0,1,2.... if not same again 0 instead of need use fields firstname , lastname.. please me!! thanks!!

parse line know values of firstname , lastname
each line. each line use e.g. firstname + "###" + lastname
key of map. values in map e.g. integer values
(these counts). when reading line, construct key , see if it
in map already. if yes - increase value i.e. count, otherwise
add new entry in map count=1.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -