में एक लिंक्डलिस्ट में जोड़ना मैं एक हैशपैप के भीतर एक लिंक्डलिस्ट में जोड़ना चाहता हूं। पूर्व जॉन: -> जैक -> काला -> दरार सुसान: -> सैली, सैमी, मूर्खतापूर्ण ectएक हैश मैप <स्ट्रिंग, लिंक्डलिस्ट>
इम काफी नहीं है कि यह कैसे करना सुनिश्चित करें। क्या मुझे प्रत्येक नाम के लिए एक नई लिंक्डलिस्ट चाहिए और यदि ऐसा है तो मैं गतिशील रूप से एक कैसे बना सकता हूं। कोशिश करने के लिए मैंने कुछ नमूना कोड दिया है।
import java.util.*;
import java.io.*;
public class test {
public static void main(String args[]) throws FileNotFoundException{
HashMap<String, LinkedList<String>> testMap = new HashMap<String, LinkedList<String>>();
File testFile = new File("testFile.txt");
Scanner enterFile = new Scanner(testFile);
String nextline = "";
LinkedList<String> numberList = new LinkedList<String>();
int x = 0;
while(enterFile.hasNextLine()){
nextline = enterFile.nextLine();
testMap.put(nextline.substring(0,1),numberList);
for(int i = 1; i < nextline.length() - 1; i++){
System.out.println(nextline);
testMap.put(nextline.substring(0,1),testMap.add(nextline.substring(i,i+1)));
}
x++;
}
LinkedList<String> printHashList = new LinkedList<String>();
printHashList = testMap.get(1);
if(printHashList.peek() != "p"){
System.out.println(printHashList.peek());
}
}
}
srry अगर यह एक अच्छी पोस्ट यह मेरा पहला एक
यह मैंने देखा है कई की तुलना में काफी बेहतर पहली पोस्ट है, अच्छा काम – Neilos