Results 1 to 14 of 14
Thread: Need help urgent!!!
- 03-18-2011, 02:22 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 44
- Rep Power
- 0
Need help urgent!!!
private ArrayList<newspaper> list;
public void addToAll(news n)
{
for(newspaper np : list){
np.addNews(n);
}
}
As u can see the code above i have an arraylist where i can store the object of class newspaper and im passing an another object in method addToAll() what i want from you guys is only can somebody explain me this code and can i do any another way for for loop not like newspaper np :list but another way.
I really appreciate that.
i
I think u have got my idea.
- 03-18-2011, 02:29 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Don't put urgent in your title, less people will help out. However, this is called a for each loop. Try looking Ito a regular loop to loop through the list.
- 03-18-2011, 02:31 AM #3
I believe you have been told before about marking your threads as urgent.
I'll get back to you as soon as I feel like it not when you demand it!
- 03-18-2011, 03:45 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 44
- Rep Power
- 0
Sorry guys for that word urgent.
Anyway hope u guys will give me any explonation of this code.
- 03-18-2011, 03:53 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I gave an extremely vague answer. The question isn't that challenging. That code uses a special loop called a for:each loop.
In this example it means, for each newspaper in list, do something.
You can also use a standard loop which takes the form of
Java Code:for(declaration; condition; step){ //do something }
- 03-18-2011, 03:56 AM #6
Or use a while loop and an Iterator.
- 03-18-2011, 03:59 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
^^that too, hope we helped you out.
- 03-18-2011, 04:53 AM #8
Member
- Join Date
- Feb 2011
- Posts
- 44
- Rep Power
- 0
still not clear :S.
I knew that that loop it makes to add news in every of object in list but the problem is how can i write in different way this.
Please I need code for this method not only //do something statements .
- 03-18-2011, 04:56 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
we try not to give code here, replace where I said //do something with your own code, it's really not very difficult.
- 03-18-2011, 04:58 AM #10
What kind of code you are expecting, another way of loop or some if/else just give some idea so that your problem can be solved and explain some more
sanjeev,संजीव
- 03-18-2011, 05:44 AM #11
Member
- Join Date
- Feb 2011
- Posts
- 44
- Rep Power
- 0
im expecting any another code instead of this one
for(newspaper np : list){
np.addNews(n);
Is there any another method how to do this ???
I need only the loop statemtn not the block statement;
If u say use while or for loop this is not help bc i know that there is while and for bu the problem is how to pass an obj like im passing here in for loop.
i think u got it guys.
- 03-18-2011, 05:48 AM #12
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
No, I don't really understand it, there is no way(besides loops) to traverse an unknown sized list and perform some operation at each step.
- 03-18-2011, 05:49 AM #13
You can do it :
1. Using Iterator
2. Normal for loop
3. Do/ while loop
Or you do not want to use thesesanjeev,संजीव
- 03-18-2011, 05:59 AM #14
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I suppose you could enforce that the list is a set size, and manually hard code the changes, however; this would be an absolutely TERRIBLE(with lots and lots of emphasis on how bad of a way it is) way to do this.
I am also hesitant to suggest this way in fear that you won't realize just how wrong it is and implement this way.
This is basically what loops make easy, since you are doing a repetitive task, using some form of loop(while, do while, or for) is the greatest way to do this.
Similar Threads
-
[URGENT]SHA Encryption System...need urgent helps
By java_idiot in forum New To JavaReplies: 6Last Post: 05-02-2010, 10:04 AM -
Help Urgent pls pls pls!!!!
By jammyjamsticy in forum Java 2DReplies: 5Last Post: 05-06-2009, 10:55 PM -
Urgent Help!!
By Winniee in forum New To JavaReplies: 5Last Post: 02-17-2009, 03:32 AM -
Hi, need some urgent help!
By jdark in forum New To JavaReplies: 2Last Post: 04-18-2008, 06:50 AM -
Help me ...urgent!
By googgoo in forum New To JavaReplies: 7Last Post: 04-05-2008, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks