mapping - Printing from MAP in JAVA -


i want print data i've passed map text file. however, when print data, program prints lines twice. there way fix it? want print data in exact way, no duplicates.

import java.io.bufferedreader; import java.io.filereader; import java.io.ioexception; import java.nio.file.path; import java.nio.file.paths; import java.util.*;  public class readtohashmap {     public static void main(string[] args) throws exception      {          map<string, string> map = new hashmap<>();         final bufferedreader bufferedreader = new bufferedreader(new filereader("c:\\documents , settings\\stajn\\desktop\\cache_son\\cache\\testing.txt"));              if (bufferedreader != null) {             string line;            while ((line = bufferedreader.readline()) != null) {              string parts[] = line.split("\n");              map.put(parts[0],parts[0]);                }              bufferedreader.close();               iterator iterator = map.keyset().iterator();            while (iterator.hasnext())      {           string key = iterator.next().tostring();           string value = map.get(key).tostring();            system.out.println(key + " " + value);       }           }       } } 

you putting in map

 map.put(parts[0],parts[0]);  

so here key , value same.when print

 system.out.println(key + " " + value);   

both print same.

do need ?

 system.out.println("value=" + value);   

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -