SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Sindhu Kodoor wrote:You mean to say use something like this :
I am still using for loop as I do not know at which index of the list the value "1" or "2" appears
Sindhu Kodoor wrote:Does the above code look better?
Only slightly. I would suggest you go through the code with a fine-toothed comb and find which parts are never actually used.Sindhu Kodoor wrote:Does the above code look better?
Sindhu Kodoor wrote:Problem is : I have a list say its of type String and values "3,4,5,6,1,7" , I need to iterate through this list and check if the list contains either value "1" or "2", but both will not be present at a time. So , I am using if else statements, and In case "1" is present I need to replace a String value x which is initially empty or null to "1", and if 1 is not present but 2 is present then replace x value to 2, if both are not present x value will returned as empty string.
Sindhu Kodoor wrote:are you suggesting instead of the for loop to use iterator.hasNext()?
Sindhu Kodoor wrote:yes, the println statements are only used for debugging purpose, I don't need to print anything.
Sindhu Kodoor wrote:yes I absolutely agree, thats why I had used the break statements earlier, instead of break how do I get out of the loop?
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|