• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in checking with forloop condition and checking if the values i entered matches  RSS feed

 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I already have a method where i store some id values. They are
1
2
3
4
If i give input
1
2

I must get output
Action
Not set
I want to check with ids.size() with which gives error for me.

Please help me to get correct values as output.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be having both the values in that. But what happens to the value being assigned to Ids_group variable? You start that loop, it gets the first value, loop continues it gets next value. So it will always contain the last element retrieved from the enumeration. Now suppose the element received is 2, and in that String array you have values 1 and 2. 2 is not matched with 1 it displays and not set, the for loop continues, the next element in that string array is 2 which matches with 2 and displays Not set. Correct me if I am wrong.
 
Edwin Torres
Ranch Hand
Posts: 57
Java Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add these two statements to your method to see if the values are truly what you expect:
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I added those two statement and I get the following result
1
first >1<
second >1<
2
first >1<
second >2<

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've a couple of remarks about your code:

Variable names should startw ith a lowercase letter.
You could generify the enumeration which will make the cast redundant.
Or you could switch to an Iterator which then can be used with a enhanced for loop.

Your variable names aren't very clear:
dbid
ids_group
ids
strids

I'm seeing so many id's. I would know what is what after a day or two after I wrote it.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you notice this
first >1

and try to match with comments I have given.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!