I am trying to access the CSV file's data using the Java and Apache commons CSV library. I am stucked in a problem. The problem is: "To Display the data of particular row if "Name" Header is equal to the "rahul". when I run the code nothing is printed out there."
The data in exportdata.csv file is :
- Name,Food,Phone
- rahul,Rice,9876416884
- ram,Egg,8437123456
- rohit,Burger,9814125755
- amit,chicken,8568934464
And my code is :
public class csvexample {
 public void readfile()
 {
    FileResource fr=new FileResource();
    CSVParser parser=fr.getCSVParser();
    for(CSVRecord record : parser)
    {
        String str=record.get("Name");
        System.out.println(str);
        if(str=="rahul")
        {
        System.out.print(record.get("Name") + "    ");
        System.out.print(record.get("Phone") + "    ");
        System.out.println(record.get("Food"));
        }          
    }
}
I think that the error is in the line if(str=="rahul") , I have checked that the program is not treating the str and "rahul" same when str="rahul" in First iteration of for loop.
 
     
     
    