Reputation: 25
I want to compare the string typed by user and another string which I formatted from date to string for an excel value. I have an array of objects. Each objects has date data. I want to print these objects from the date typed by user. However, the method that I wrote for finding the index of the object is not working properly. I hope you got me. Here is my code; `
System.out.print("Please enter a date:");
input = new Scanner(System.in);
String date1=input.next();
int index_tarih=searching(date1, myObjects);//myObjects is my array storing my data from excel.
public static int searching(String datess,sicaklik_nesne dayss[])
{ int number=0;
for(int index_number=0;index_number<dayss.lenght;index_number++)
{
if(dayss[index_number].Gun==datess)
{
sayi=9;
}
}
enter code here
return sayi;
}
`
i.Gun=new DataFormatter().formatCellValue(cell);// this code from my class retrieving excel data.
Upvotes: -1
Views: 47
Reputation: 768
Please use equals instead of == while comparing strings
if(dayss[index_number].Gun.equals(datess)) {
sayi=9;
}
PS: if you want to compare Strings doesn't matter it is uppercase or lowercase you can use equalsIgnoreCase()
method instead of equals here.
Upvotes: 0