Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: Parse part file

  1. #1
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default Parse part file

    Hi Guys, how could i parse a specific elements from a .part file using java.
    BEGIN:VCARD
    VERSION:3.0
    N:Arun_niit;;
    FN:Arun_niit
    EMAIL;type=internet:nura_ice@yahoo.co.in
    END:VCARD
    BEGIN:VCARD
    VERSION:3.0
    N:Bống Mũn;Hải;
    FN:Hải Anh Bống Mũn
    END:VCARD
    BEGIN:VCARD
    VERSION:3.0
    N:Colombo;Giorgia;
    FN:Giorgia Colombo
    EMAIL;type=internet:giorgiacolombo89@libero.it
    END:VCARD

    This is the content and I want to read "N: FN: Email:" and put in an array and show the output.

    This is my code and i'm not familiarized with split, scan, useDelimiter in java. I need some assistance.

    Thank you guys.

    Java Code:
    //This code just reads all the line without the : symbol.
    import java.io.*;
    import java.util.Scanner;
    
    public class ReadWithScanner {
    
      public static void main(String... aArgs) throws FileNotFoundException {
        ReadWithScanner parser = new ReadWithScanner("D:/Hfm.part");
        parser.processLineByLine();
        //log("Done.");
      }
      
      /**
       Constructor.
       @param aFileName full name of an existing, readable file.
      */
      public ReadWithScanner(String aFileName){
        fFile = new File(aFileName);  
      }
      
      /** Template method that calls {@link #processLine(String)}.  */
      public final void processLineByLine() throws FileNotFoundException {
        //Note that FileReader is used, not File, since File is not Closeable
        Scanner scanner = new Scanner(new FileReader(fFile));
        try {
          //first use a Scanner to get each line
          while ( scanner.hasNextLine() ){
            processLine( scanner.nextLine() );
          }
        }
        finally {
          //ensure the underlying stream is always closed
          //this only has any effect if the item passed to the Scanner
          //constructor implements Closeable (which it does in this case).
          scanner.close();
        }
      }
      
      /** 
       Overridable method for processing lines in different ways.
        
    BEGIN:VCARD
    VERSION:3.0
    N:Arun_niit;;
    FN:Arun_niit
    EMAIL;type=internet:nura_ice@yahoo.co.in
    END:VCARD
      **/
      protected void processLine(String aLine){
        //use a second Scanner to parse the content of each line 
        Scanner scanner = new Scanner(aLine);
        scanner.useDelimiter(":");
        if ( scanner.hasNext() ){
          String name = scanner.next();
          String value = scanner.next();
          log("Name is : " + quote(name.trim()) + ", and Value is : " + quote(value.trim()) );
          //log("Value is : " + quote(value.trim()));
        }
        else {
          log("Empty or invalid line. Unable to process.");
        }
        //no need to call scanner.close(), since the source is a String
      }
      
      // PRIVATE 
      private final File fFile;
      
      private static void log(Object aObject){
        System.out.println(String.valueOf(aObject));
      }
      
      private String quote(String aText){
        //String QUOTE = "'";
        //return QUOTE + aText + QUOTE;
    	  return aText; 
      }
    }

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    What happens with your current code? Errors? Exceptions? Something else?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Everything is fine. I would like to read "N: FN: Email:" from the file and put it in an array. I don't know how to do it using split or using Delimiter. Delimiter, no option to delimit the characters. so, i have to use "split" to do this. I need some assistance from this. thank you.

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Here is what API documentation has to say about it : String.split()

    You can also search the web for the example which can give you better idea. Here is one that I found : Java String Split Example

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Thank u very much for your help. if you could tell me how could i read those elements from a file. Thank

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,572
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by karthinkin View Post
    Thank u very much for your help. if you could tell me how could i read those elements from a file. Thank
    Maybe the following little method can help you out (halfway); it reads a String line and a prefix (also a String). If the prefix exists in the line it returns the suffix of the line, otherwise it returns null. Here it is:

    Java Code:
    String suffix(String line, String prefix) {
       int l= prefix.length();
       if (line.startsWith(prefix))
          return line.substring(l);
       return  null;
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    thnak U. It helps.

  9. #9
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default Help

    Guys at last I'm able to read information from the file but not appropriately:

    Java Code:
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    
    public class exam {
    
    	public static void main(String[] args) throws Exception {
    		
    		// File path & name
    		String filepath = ("D:/Hfm.part");
    		
    		// Read in file to determine how many lines it has
    		FileInputStream in = new FileInputStream(filepath);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String strLine;
    		int counter = 0;
    		
    		while ((strLine = br.readLine()) != null)
    		{
    			counter++;
    		}
    			
    		in.close();
    		
    		// Read in file
    		FileInputStream in2 = new FileInputStream(filepath);
    		BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
    		String strLine2;
    		
    		// Declare array
    		String[] myarray;
    		myarray = new String[counter];
    			
    			// Add each line to the array
    			for (int i = 0; i < myarray.length; i++){
    				myarray[i] = br2.readLine();
    			}
    		
    		in2.close();
    		
    		// Loop through array looking for the correct text, format & print
    		for (int c = 0; c < myarray.length; c++){
    			
    			if(myarray[c].contains("BEGIN:VCARD") || myarray[c].contains("") ){
    								
    				String[] split = myarray[c+1].split(" ");
    				
    				String contacts1 = "";
    				
    				for (int i = 0; i < split.length; i++){
    					if (split[i].contains("N:") &! split[i].contains("-")){
    						contacts1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("FN:") &! split[i].contains("-")){
    						contacts1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("EMAIL;") &! split[i].contains("-")){
    						contacts1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("TEL") &! split[i].contains("-")){
    						contacts1 = split[i].replace("\"", "");
    					}
    					if (split[i].contains("URL;type") &! split[i].contains("-")){
    						contacts1 = split[i].replace("\"", "");
    					}
    						
    					}
    											
    				System.out.println(contacts1); 
    			}
    
    		}
    	}
    }
    My output is :

    Java Code:
    
    BEGIN:VCARD
    VERSION:3.0
    N:Veera_Kumar;;
    FN:Veera_Kumar
    EMAIL;type=internet:KUMARg_81@yahoo.com
    
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 88
    	at exam.main(exam.java:46)
    Still i want to remove the first 2 lines of my output and the error. Thank U guys.

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,572
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by karthinkin View Post
    Guys at last I'm able to read information from the file but not appropriately:

    Java Code:
    			if(myarray[c].contains("BEGIN:VCARD") || myarray[c].contains("") ){
    								
    				String[] split = myarray[c+1].split(" ");
    I'm sure the last line of the file (so the last entry in your array) contains the empty String "".

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 88
    at exam.main(exam.java:46)
    Do you understand the error message? Look at line 46 in the exam.java file.
    Is there an array used there?
    Does the array have 88 elements? The code is trying to get to it.

    Look at the index to the array and be sure that it does NOT exceed the size of the array.

  12. #12
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Got it & fixed the problem. Thank U.

  13. #13
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Guys, I'm able to parse the file right now. I need some assistance that how can i make a Hashmap/Hashtable from the output.
    For example
    BEGIN:VCARD
    VERSION:3.0
    N:Rangarajkarthik
    FN:karthik Rangaraj
    EMAIL:kart2006@gmail.com
    EMAIL:karthikrangaraj@yahoo.com
    END:VCARD

    From the above sample output, how can i make an id for the name and store those email address corresponding to the name.
    Ideas and Help will be highly appreciated. Thank u guys.

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,572
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by karthinkin View Post
    Guys, I'm able to parse the file right now. I need some assistance that how can i make a Hashmap/Hashtable from the output.
    For example
    BEGIN:VCARD
    VERSION:3.0
    N:Rangarajkarthik
    FN:karthik Rangaraj
    EMAIL:kart2006@gmail.com
    EMAIL:karthikrangaraj@yahoo.com
    END:VCARD

    From the above sample output, how can i make an id for the name and store those email address corresponding to the name.
    Ideas and Help will be highly appreciated. Thank u guys.
    If all the lines are of the form key:value where both key and value don't contain a colon you can do this:

    Java Code:
    Map<String, String> map= new HasMap<String, String>();
    BufferedReader br= // a reader for your data
    for (String line; (line= br.readLine()) != null;) {
       String[] pair= line.split(":");
       map.put(pair[0], pair[1]);
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Thanks a lot for the idea.

    Name Gmail Facebook Yahoo Aol

    [ unless you like viagra, don't put your email addresses here ]

    I want to make a table like this using HashMap Array linkedlist from the output.

    BEGIN:VCARD
    VERSION:3.0
    N:Rangarajkarthik
    FN:karthik Rangaraj
    EMAIL:kart2006@gmail.com
    EMAIL:karthikrangaraj@yahoo.com
    END:VCARD

    BEGIN:VCARD
    VERSION:3.0
    N:Veera_Kumar
    FN:Veera_Kumar
    EMAIL:KUMARg_81@yahoo.com
    END:VCARD

    Here is the link for my list : http://tinypic.com/r/14d1w1x/7
    Any Ideas?
    Last edited by JosAH; 05-31-2011 at 10:26 AM. Reason: email addresses removed

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,572
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by karthinkin View Post
    Any Ideas?
    Ideas for what?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Map<String, String> map= new HasMap<String, String>();

    From this i can map only two values but if u check my image or the kind of table what i want to make it has 5 values. So, i'm confused! :(

    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class HashMapText {
        public static void main(String[] args) throws IOException {
    
            Map<String, String> map= new HashMap<String, String>();
            BufferedReader br= new BufferedReader(new FileReader( "D:/latestcontact.part"));
            for (String line; (line= br.readLine()) != null;) {
               String[] pair= line.split(":");
               map.put(pair[0], pair[1]);
            }
            System.out.println();
        }
    }
    I have started like this§
    Last edited by karthinkin; 05-31-2011 at 10:44 AM. Reason: java code added

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    what i want to make it has 5 values
    Create you own class to hold those 5 values and put an instance of that class in the Map

  19. #19
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Guys, finally i managed to create a hashtable in the base class itself. And created two sub classes to generate an output using hashtable.
    Here is my code :

    Java Code:
    Exam.Java
    
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.Hashtable;
    
    
    public class exam {
    
    	public static void main(String[] args) throws Exception {
    		
    		// File path & name
    		String filepath = ("D:/cotntactsnew.part");
    		
    		// Read in file to determine how many lines it has
    		FileInputStream in = new FileInputStream(filepath);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		@SuppressWarnings("unused")
    		String strLine;
    		int counter = 0;
    		while ((strLine = br.readLine()) != null)
    		{
    			counter++;
    		}
    			
    		in.close();
    		
    		// Read in file
    		FileInputStream in2 = new FileInputStream(filepath);
    		BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
    		@SuppressWarnings("unused")
    		String strLine2;
    		
    		// Declare array
    		String[] myarray;
    		myarray = new String[counter];
    			
    			// Add each line to the array
    			for (int i = 0; i < myarray.length; i++){
    				myarray[i] = br2.readLine();
    			}
    		
    		in2.close();
    		
    		// Loop through array looking for the correct text, format & print
    		for (int c = 0; c < myarray.length; c++){
    			//System.out.println("");
    			if(myarray[c].contains("")) { //| myarray[c].contains("") )
    								
    				String[] split = myarray[c].split(" ");
    				
    				String contacts = " ";
    				//System.out.println("");
    				for (int i = 0; i < split.length; i++){
    					if (split[i].contains("N:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("FN:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("EMAIL:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("TEL:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("URL:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					/*if (split[i].contains("END:") &! split[i].contains("-")){
    						contacts = split[i].replace("\"", "");
    					}*/
    					}
    											
    				System.out.println(contacts); 
    				
    				
    				Hashtable<Integer,Person> hmap= new Hashtable<Integer,Person>();
    				
    			}
    
    		}
    	}
    
    	@Override
    	public String toString() {
    		return "exam [getClass()=" + getClass() + ", hashCode()=" + hashCode()
    				+ ", toString()=" + super.toString() + "]";
    	}
    }
    
    Person.java
    
    
    import java.lang.String; 
    public class Person {
    String Name;
    String FName; 
    
    Contat ct = new Contat();
    
    public String getName() {
    	
    	return Name;
    }
    
    public void setName(String name) {
    	Name = name;
    }
    
    public String getFName() {
    	return FName;
    }
    
    public void setFName(String fName) {
    	FName = fName;
    }
    
    public Contat getCt() {
    	return ct;
    }
    
    public void setCt(Contat ct) {
    	this.ct = ct;
    }
    
    @Override
    public int hashCode() {
    	final int prime = 31;
    	int result = 1;
    	result = prime * result + ((FName == null) ? 0 : FName.hashCode());
    	result = prime * result + ((Name == null) ? 0 : Name.hashCode());
    	result = prime * result + ((ct == null) ? 0 : ct.hashCode());
    	return result;
    }
    
    @Override
    public boolean equals(Object obj) {
    	if (this == obj)
    		return true;
    	if (obj == null)
    		return false;
    	if (getClass() != obj.getClass())
    		return false;
    	Person other = (Person) obj;
    	if (FName == null) {
    		if (other.FName != null)
    			return false;
    	} else if (!FName.equals(other.FName))
    		return false;
    	if (Name == null) {
    		if (other.Name != null)
    			return false;
    	} else if (!Name.equals(other.Name))
    		return false;
    	if (ct == null) {
    		if (other.ct != null)
    			return false;
    	} else if (!ct.equals(other.ct))
    		return false;
    	return true;
    }
    
    @Override
    public String toString() {
    	return "Person [Name=" + Name + ", FName=" + FName + ", ct=" + ct + "]";
    }
    
    
    }
    
    
    Contat.java
    
    
    
    public class Contat {
    	
    		 String Facebook;
    		 String Gmail;
    		 String Yahoo;
    		 String Url;
    		public String getFacebook() {
    			return Facebook;
    		}
    		public void setFacebook(String facebook) {
    			Facebook = facebook;
    		}
    		public String getGmail() {
    			return Gmail;
    		}
    		public void setGmail(String gmail) {
    			Gmail = gmail;
    		}
    		public String getYahoo() {
    			return Yahoo;
    		}
    		public void setYahoo(String yahoo) {
    			Yahoo = yahoo;
    		}
    		public String getUrl() {
    			return Url;
    		}
    		public void setUrl(String url) {
    			Url = url;
    		}
    		@Override
    		public int hashCode() {
    			final int prime = 31;
    			int result = 1;
    			result = prime * result
    					+ ((Facebook == null) ? 0 : Facebook.hashCode());
    			result = prime * result + ((Gmail == null) ? 0 : Gmail.hashCode());
    			result = prime * result + ((Url == null) ? 0 : Url.hashCode());
    			result = prime * result + ((Yahoo == null) ? 0 : Yahoo.hashCode());
    			return result;
    		}
    		@Override
    		public boolean equals(Object obj) {
    			if (this == obj)
    				return true;
    			if (obj == null)
    				return false;
    			if (getClass() != obj.getClass())
    				return false;
    			Contat other = (Contat) obj;
    			if (Facebook == null) {
    				if (other.Facebook != null)
    					return false;
    			} else if (!Facebook.equals(other.Facebook))
    				return false;
    			if (Gmail == null) {
    				if (other.Gmail != null)
    					return false;
    			} else if (!Gmail.equals(other.Gmail))
    				return false;
    			if (Url == null) {
    				if (other.Url != null)
    					return false;
    			} else if (!Url.equals(other.Url))
    				return false;
    			if (Yahoo == null) {
    				if (other.Yahoo != null)
    					return false;
    			} else if (!Yahoo.equals(other.Yahoo))
    				return false;
    			return true;
    		}
    		@Override
    		public String toString() {
    			return "Contat [Facebook=" + Facebook + ", Gmail=" + Gmail
    					+ ", Yahoo=" + Yahoo + ", Url=" + Url + "]";
    		}	
    
    }
    Now, how could i instantiate the output of my example class to the hashmap and how could i give an automatic id generation for each record.

    For ex : ID 1 Karthik kart2006@gmail.com karthikrangaraj@yahoo.com.


    Thaning u guys.

  20. #20
    karthinkin is offline Member
    Join Date
    May 2011
    Posts
    13
    Rep Power
    0

    Default

    Guys, finally i managed to create a hashtable in the base class itself. And created two sub classes to generate an output using hashtable.
    Here is my code :

    Java Code:
    Exam.Java
    
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.Hashtable;
    
    
    public class exam {
    
    	public static void main(String[] args) throws Exception {
    		
    		// File path & name
    		String filepath = ("D:/cotntactsnew.part");
    		
    		// Read in file to determine how many lines it has
    		FileInputStream in = new FileInputStream(filepath);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		@SuppressWarnings("unused")
    		String strLine;
    		int counter = 0;
    		while ((strLine = br.readLine()) != null)
    		{
    			counter++;
    		}
    			
    		in.close();
    		
    		// Read in file
    		FileInputStream in2 = new FileInputStream(filepath);
    		BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
    		@SuppressWarnings("unused")
    		String strLine2;
    		
    		// Declare array
    		String[] myarray;
    		myarray = new String[counter];
    			
    			// Add each line to the array
    			for (int i = 0; i < myarray.length; i++){
    				myarray[i] = br2.readLine();
    			}
    		
    		in2.close();
    		
    		// Loop through array looking for the correct text, format & print
    		for (int c = 0; c < myarray.length; c++){
    			//System.out.println("");
    			if(myarray[c].contains("")) { //| myarray[c].contains("") )
    								
    				String[] split = myarray[c].split(" ");
    				
    				String contacts = " ";
    				//System.out.println("");
    				for (int i = 0; i < split.length; i++){
    					if (split[i].contains("N:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("FN:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("EMAIL:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("TEL:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					if (split[i].contains("URL:") &! split[i].contains(";")){
    						contacts = split[i].replace("\"", "");
    					}
    					/*if (split[i].contains("END:") &! split[i].contains("-")){
    						contacts = split[i].replace("\"", "");
    					}*/
    					}
    											
    				System.out.println(contacts); 
    				
    				
    				Hashtable<Integer,Person> hmap= new Hashtable<Integer,Person>();
    				
    			}
    
    		}
    	}
    
    	@Override
    	public String toString() {
    		return "exam [getClass()=" + getClass() + ", hashCode()=" + hashCode()
    				+ ", toString()=" + super.toString() + "]";
    	}
    }
    
    Person.java
    
    
    import java.lang.String; 
    public class Person {
    String Name;
    String FName; 
    
    Contat ct = new Contat();
    
    public String getName() {
    	
    	return Name;
    }
    
    public void setName(String name) {
    	Name = name;
    }
    
    public String getFName() {
    	return FName;
    }
    
    public void setFName(String fName) {
    	FName = fName;
    }
    
    public Contat getCt() {
    	return ct;
    }
    
    public void setCt(Contat ct) {
    	this.ct = ct;
    }
    
    @Override
    public int hashCode() {
    	final int prime = 31;
    	int result = 1;
    	result = prime * result + ((FName == null) ? 0 : FName.hashCode());
    	result = prime * result + ((Name == null) ? 0 : Name.hashCode());
    	result = prime * result + ((ct == null) ? 0 : ct.hashCode());
    	return result;
    }
    
    @Override
    public boolean equals(Object obj) {
    	if (this == obj)
    		return true;
    	if (obj == null)
    		return false;
    	if (getClass() != obj.getClass())
    		return false;
    	Person other = (Person) obj;
    	if (FName == null) {
    		if (other.FName != null)
    			return false;
    	} else if (!FName.equals(other.FName))
    		return false;
    	if (Name == null) {
    		if (other.Name != null)
    			return false;
    	} else if (!Name.equals(other.Name))
    		return false;
    	if (ct == null) {
    		if (other.ct != null)
    			return false;
    	} else if (!ct.equals(other.ct))
    		return false;
    	return true;
    }
    
    @Override
    public String toString() {
    	return "Person [Name=" + Name + ", FName=" + FName + ", ct=" + ct + "]";
    }
    
    
    }
    
    
    Contat.java
    
    
    
    public class Contat {
    	
    		 String Facebook;
    		 String Gmail;
    		 String Yahoo;
    		 String Url;
    		public String getFacebook() {
    			return Facebook;
    		}
    		public void setFacebook(String facebook) {
    			Facebook = facebook;
    		}
    		public String getGmail() {
    			return Gmail;
    		}
    		public void setGmail(String gmail) {
    			Gmail = gmail;
    		}
    		public String getYahoo() {
    			return Yahoo;
    		}
    		public void setYahoo(String yahoo) {
    			Yahoo = yahoo;
    		}
    		public String getUrl() {
    			return Url;
    		}
    		public void setUrl(String url) {
    			Url = url;
    		}
    		@Override
    		public int hashCode() {
    			final int prime = 31;
    			int result = 1;
    			result = prime * result
    					+ ((Facebook == null) ? 0 : Facebook.hashCode());
    			result = prime * result + ((Gmail == null) ? 0 : Gmail.hashCode());
    			result = prime * result + ((Url == null) ? 0 : Url.hashCode());
    			result = prime * result + ((Yahoo == null) ? 0 : Yahoo.hashCode());
    			return result;
    		}
    		@Override
    		public boolean equals(Object obj) {
    			if (this == obj)
    				return true;
    			if (obj == null)
    				return false;
    			if (getClass() != obj.getClass())
    				return false;
    			Contat other = (Contat) obj;
    			if (Facebook == null) {
    				if (other.Facebook != null)
    					return false;
    			} else if (!Facebook.equals(other.Facebook))
    				return false;
    			if (Gmail == null) {
    				if (other.Gmail != null)
    					return false;
    			} else if (!Gmail.equals(other.Gmail))
    				return false;
    			if (Url == null) {
    				if (other.Url != null)
    					return false;
    			} else if (!Url.equals(other.Url))
    				return false;
    			if (Yahoo == null) {
    				if (other.Yahoo != null)
    					return false;
    			} else if (!Yahoo.equals(other.Yahoo))
    				return false;
    			return true;
    		}
    		@Override
    		public String toString() {
    			return "Contat [Facebook=" + Facebook + ", Gmail=" + Gmail
    					+ ", Yahoo=" + Yahoo + ", Url=" + Url + "]";
    		}	
    
    }
    Now, how could i instantiate the output of my example class to the hashmap and how could i give an automatic id generation for each record.

    For ex : ID-1 Karthik kart2006@gmail.com karthikrangaraj@yahoo.com.


    Thaning u guys.

Page 1 of 2 12 LastLast

Similar Threads

  1. Parse file into arrayList
    By zenitis in forum New To Java
    Replies: 8
    Last Post: 05-02-2011, 08:01 AM
  2. help to parse an xhtml file
    By nijil in forum New To Java
    Replies: 0
    Last Post: 02-20-2010, 10:37 AM
  3. How to parse a .db file ?
    By aminov in forum JDBC
    Replies: 0
    Last Post: 08-06-2009, 04:11 PM
  4. Replies: 7
    Last Post: 05-23-2008, 03:46 AM
  5. how to parse an xml file
    By oregon in forum XML
    Replies: 3
    Last Post: 08-01-2007, 04:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •