Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Define loop in another method

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-03-2010
Member
 
Join Date: Dec 2009
Posts: 178
Define loop in another method
  

Hello,
I have a loop in a method1 () that lets you scan a file and retrieve data from a given "for (Event e: file)" eg. My question is I want to know if we can put this loop into another method, method2 (Event e) and instead of integrating the loop in method1 (). I integrate method2 (e) in method1 (). I do not know this is possible or not, but I think this can be done, so if you guys have any idea about this then please post back. Thanks in advance.

Reply With Quote
  #2  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 343
Re: Define loop in another method

Hello,
Yes you can call a parametrized method within another method, it is even advisable to separate your application with atomic methods, to facilitate reuse. I do not see what could make you believe that it is not possible? Is this a concern for performance? If yes, performance is managed by the compiler, in theory, and compiler byte code, sun is powerful enough to optimize this kind of thing. But personally I do not feel any need of doing this in a code, but if you still wish you can use it.
Reply With Quote
  #3  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Define loop in another method

Hello,
The following may help you, just have a look at it
Code:
Public void method() {

   List mlst = <Event> null;
   / / Get your list;

   traitementListe(mlst);
 
}
 
private void traitementListe(List mlst <Event>) {
   for(Event e: mlst) {
      trtment(e);
   }
}
 
private void trtment(Event e) {
   / / Here the method of processing an element in your loop
}
Reply With Quote
  #4  
Old 05-03-2010
Member
 
Join Date: Dec 2009
Posts: 296
Re: Define loop in another method

Hello,
I am also new to java, but I would have done something like this
Code:
Public void method() {

   Event e = null
 
   this.trtment(e);
    / / processing on e
 
}
 
private void trtment(Event e) {
   for(Event e: file) 
     e = e;
     return e;
   
}
Reply With Quote
  #5  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Define loop in another method

Hello,
This is a well defined code, you can try this
Code:
Public class myclass {
  private Collection <Event> e;

  / / The getter in your private member
  Public Collection <Event> geteve() {
    return e;
  }
 
  Public void charger(String file) {
    / / Read the file
    BufferedReader mfl = new BufferedReader(new FileReader(file));

    String line = null;
    while(line = mfl.readLine() != null) {
      Event eve = new Event();
      eve.setName(row.substring(1,10));
      e.add(eve);
    }
  }
 
  Public static void hand(String[] args) {
    myclass MyClass = new myclass();
    MyClass.charger("myListEvent.txt");
    
  }
}
Reply With Quote
  #6  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Define loop in another method

Hello,
I think you can even use the enums here to do the same thing. Have a look at the following, though I am not sure that this is what you want.
Code:
 public static enum etyp {  
     COMPONENT_ADDED,  
   COMPONENT_REMOVED;  

   public static boolean cnt(etyp eventType) {  
        boolean cnt = false;  
        etyp[] vals = etyp.vals();  
   
        for (int i = 0; i < vals.length && !cnt; i++) {  
            cnt = (COMPONENT_ADDED.equals(vals[i]) || COMPONENT_REMOVED  
                     .equals(vals[i]));  
       }  
   
        return cnt;  
     }  
 }
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Define loop in another method"
Thread Thread Starter Forum Replies Last Post
Watercooling: Single loop or Dual Loop Akolekar Hardware Peripherals 3 21-10-2011 10:52 PM
Reboot Loop in Windows 7 Reboot loop and Safe mode doesn't work mADiRAkSHii Operating Systems 4 25-01-2011 06:23 PM
Method overriding versus method hiding in C# ^MALARVIZHI^ Software Development 4 25-12-2010 05:25 AM
Is it possible to call destroy() method within init() Method? Level8 Software Development 3 10-12-2009 07:36 AM
What is method overriding and method overloading in java beelow Software Development 3 17-11-2009 07:20 AM


All times are GMT +5.5. The time now is 11:50 AM.