How to rewrite iterator code to for/in code ?

I am trying to change my iterator code to code using the for/in construct from Java 1.5
in the howManyMessages() method I am trying to convert:
Iterator it = messages.iterator();
        while(it.hasNext()) {
            MailItem mess = (MailItem) it.next();
            if(mess.getTo().equals(who)) {
                count++;
        Should this become:
for(Object mess: message)
  if(get(mess).getTo().equals(who)
      count++;  and how about the getNextMailItem() method ? it has a it.remove() statement. Is it impossible to use the for/in construct
where there is a remove() method ?
Thank you in advance. Below is the coding
import java.util.Vector;
import java.util.Iterator;
/* A simple model of a mail server. The server is able to receive
* messages for storage, and deliver them to clients on demand.
* @author David J. Barnes and Michael Kolling @version 2001.05.30 */
public class MailServer
    // Storage for the arbitrary number of messages to be stored on the server.
    private Vector messages;
     // Construct a mail server.
         public MailServer()
            messages = new Vector();
     /* @return How many messages are waiting for the given user.
     * @param who The user to check for. */
    public int howManyMessages(String who)
        int count = 0;
        Iterator it = messages.iterator();
        while(it.hasNext()) {
            MailItem mess = (MailItem) it.next();
            if(mess.getTo().equals(who)) {
                count++;
        return count;
     /* Return the next message for who. Return null if there
     * are none.
     * @param who The user requesting their next message.*/
         public MailItem getNextMailItem(String who)
           Iterator it = messages.iterator();
            while(it.hasNext())
               MailItem mess = (MailItem) it.next();
               if(mess.getTo().equals(who))
                   it.remove();
                   return mess;
         return null;
         /* Add the given message to the message list.
          * @param item The mail item to be stored on the server.*/
            public void post(MailItem item)
                 messages.add(item);
/* A class to model a simple mail item. The item has sender and recipient
* addresses and a message string.
* @author David J. Barnes and Michael Kolling
* @version 2001.05.30 */
public class MailItem
    // The sender of the item.
    private String from;
    // The intended recipient.
    private String to;
    // The text of the message.
    private String message;
     /* Create a mail item from sender to the given recipient,
     * containing the given message.
     * @param from The sender of this item.
     * @param to The intended recipient of this item.
     * @param message The text of the message to be sent. */
    public MailItem(String from, String to, String message)
        this.from = from;
        this.to = to;
        this.message = message;
      //Return The sender of this message.
         public String getFrom()
        return from;
     // Return The intended recipient of this message.
         public String getTo()
            return to;
     //Return The text of the message.
         public String getMessage()
        return message;
         // Print this mail message to the text terminal.
         public void print()
            System.out.println("From: " + from);
            System.out.println("To: " + to);
            System.out.println();
            System.out.println("Message:     " + message);
* A class to model a simple email client. The client is run by a
* particular user, and sends and retrieves mail via a particular server.
* @author David J. Barnes and Michael Kolling
* @version 2001.05.30
public class MailClient
    // The server used for sending and receiving.
    private MailServer server;
    // The user running this client.
    private String user;
     * Create a mail client run by user and attached to the given server.
    public MailClient(MailServer server, String user)
     this.server = server;
     this.user = user;
     * Return the next mail item (if any) for this user.
    public MailItem getNextMailItem()
     return server.getNextMailItem(user);
     * Print the next mail item (if any) for this user to the text
     * terminal.
    public void printNextMailItem()
     MailItem item = server.getNextMailItem(user);
     if(item == null) {
         System.out.println("No new mail.");
     else {
         item.print();
     * Send the given message to the given recipient via
     * the attached mail server.
     * @param to The intended recipient.
     * @param mess A fully prepared message to be sent.
    public void sendMessage(String to, String message)
     MailItem mess = new MailItem(user, to, message);
     server.post(mess);
//In this program we learn about the Vector class and the iterator()
//we step into the printNewMailItem() method of the MailClient class with bluej
//we observe the debugger and watch a messege appear.
public class Try_e_mail
  public static void main(String[] args)
      MailServer myMailServer = new MailServer();
      MailClient Julie = new MailClient(myMailServer, "Julie");
      MailClient Sam = new MailClient(myMailServer, "Sam");
      MailItem messageMonday = new MailItem("Sam", "Julie", "I really enjoy studying Java !");
      MailItem messageTuesday = new MailItem("Julie", "Sam", "Computer Science is an important challenge !");
      MailItem messageWednesday = new MailItem("Sam", "Julie", "It is alot more rewarding than watching TV !");
      System.out.println();
      messageMonday.print();
      System.out.println();
      messageTuesday.print();
      System.out.println();
      messageWednesday.print();
//The output I received is:
//From: Sam
//To: Julie
//Message:     I really enjoy studying Java !
//From: Julie
//To: Sam
//Message:     Computer Science is an important challenge !
//From: Sam
//To: Julie
//Message:     It is alot more rewarding than watching TV !

The for/in coding that worked was for a non-generic collection.
So I guess that means that a Vector is a non-generic collection.
What does non-generic mean ?
Thank you in advance
//for non-generic collections
       for(Object obj : messages)
          MailItem mess = (MailItem)obj;
          if ( mess.getTo().equals(who))
            count++;
  //for Generic collections                     
         /*  for(MailItem mess: messages)
             if(mess.getTo().equals(who))
               count++; */

Similar Messages

  • Please help me.. how to rewrite the following java- for loop code in ada

    int i, j, n = 100;
    for (i = 0, j = 17; i < n; i++, j-- )
    sum += i * j + 3;

    how to rewrite the following java- for loop code in ada
    You should have a programming manual for Ada first. If you mean it the other way round, I think you subject line confused me.

  • How can i rewrite this code into java?

    How can i rewrite this code into a java that has a return value?
    this code is written in vb6
    Private Function IsOdd(pintNumberIn) As Boolean
        If (pintNumberIn Mod 2) = 0 Then
            IsOdd = False
        Else
            IsOdd = True
        End If
    End Function   
    Private Sub cmdTryIt_Click()
              Dim intNumIn  As Integer
              Dim blnNumIsOdd     As Boolean
              intNumIn = Val(InputBox("Enter a number:", "IsOdd Test"))
              blnNumIsOdd = IsOdd(intNumIn)
              If blnNumIsOdd Then
           Print "The number that you entered is odd."
        Else
           Print "The number that you entered is not odd."
        End If
    End Sub

    873221 wrote:
    I'm sorry I'am New to Java.Are you new to communication? You don't have to know anything at all about Java to know that "I have an error," doesn't say anything useful.
    I'm just trying to get you to think about what your post actually says, and what others will take from it.
    what does this error mean? what code should i replace and add? thanks for all response
    C:\EvenOdd.java:31: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=true;
    ^
    C:\EvenOdd.java:35: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=false;
    ^
    2 errors
    Telling you "what code to change it to" will not help you at all. You need to learn Java, read the error message, and think about what it says.
    It's telling you exactly what is wrong. At line 31 of EvenOdd.java, you're calling isOdd(), with no arguments, but the isOdd() method requires an int argument. If you stop ant think about it, that should make perfect sense. How can you ask "is it odd?" without specifying what "it" is?
    So what is this all about? Is this homework? You googled for even odd, found a solution in some other language, and now you're just trying to translate it to Java rather than actually learning Java well enough to simply write this trivial code yourself?

  • How to find function code for buttons on toolbar in oops alv

    Hi experts,
    I want to remove some buttons from toolbar in oops alv, i know the procedure like get function code and pass the value in a table and pass that table to IT_TOOLBAR_EXCLUDING of
    method set_table_for_first_display but I WANT TO KNOW HOW TO FIND FUNCTION CODE FOR BUTTONS ON TOOLBAR IN OOPS ALV

    Hi Prakash,
    -->First you have to set the pf status in your alv program by,
    {FORM pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'FIRST'.
    ENDFORM.                    "PF_STATUS}
    -->Pass this Subroutine name in the Function module, Reuse_alv_grid_display's parameters i.e,
          i_callback_pf_status_set          = 'PF_STATUS'}
    *-->Then doble click on that pf status,
    From the menu bar, select Extras->Adjust Template->List Viewer,
    This will give you the existing statndard gui status of the program*
    ->Then catch that function codes in the User command Parameter of the Function module Reuse.. i.e,
          i_callback_user_command           = 'COMM'
    And make a subroutine of the name 'COMM'i.e,
    FORM comm USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
      DATA: okcode TYPE sy-ucomm.
      okcode = ucomm.
      CASE okcode.
        WHEN 'REF'.
        CALL FUNCTION 'POPUP_TO_INFORM'
          EXPORTING
            titel         = 'MANSI'
            txt1          = 'CREATED BY'
            txt2          = SY-UNAME
          TXT3          = ' '
          TXT4          = ' '
    endcase.
    Hope it helps you
    Regrds
    Mansi

  • How to print claim code for envy 5530 without connecting to internet?

    how to print claim code for hp envy 5530 without connecting to internet. We do not have wireless internet and we are trying to set up the eprint app for our samsun android phones and ipad. We need to print off the claim code from the printer but it seems we need to have internet for that. is there any way around that?
    Thanks

    Hi,
    You have to, without connecting to the internet, the claim code (if you can get one) is useless.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How to create t-code for a table and how to create transaction variant???

    Hi,
    I have created a custom table zsark.
    Now my requirement is : I have to create a transaction variant zsark_var for sm30 and table zsark. I have to disable the output of the first screen. I have to assign the transaction variant to the transaction code of table zsark.
    Now,
    1.     how to create transaction code to a table. Can any one give me the 
                    staps??
    2.     how to create transaction variant for the above requirement???
    Thanks & Regards,
    Sarkar

    Hi
    1 Goto SE93 transaction
    2 Choose 5th option Transaction with parameters
    3 Give transaction : SM30, Check Skip Initial Screen Press Enter
    4 Goto Bottom left corner, click F4 select viewname, on right hand side give table name
    5 Press one more time F4, choose update , mark it X on right side.
    6 save the transaction.
    Thanks
    sandeep
    reward if helpful

  • How to create transaction code for a Z-table

    How to create transaction code for a Z-table?
    Se93 --> then which radio button to be selected? and what is the program nam e to  be given

    Hi Sam,
    <b>Procedure to create a TCODE for ZTABLE:</b>
    Create a table maintainance/View for the Z* Table.
    Once you create the view goto SE93>Select Parameter transaction and give the short desc.>
    Give the transaction as SM30(Skip the first screen-optional)>Check all check boxes under GUI support>In the default values(grid)section first row give the VIEWNAME as you created initially and the second row UPDATE as X.
    <u><i>Se93 --> then which radio button to be selected</i></u>
    Select the parameter transaction as a radio button.
    <u><i>what is the program nam e to be given</i></u>
    no need to give any program name. Instead you have to give the transaction code name as SM30.
    Pls mark the helpful answers.
    Thanks
    Eswar

  • How to create transaction code for maintenance view

    hai friends,
    i hope every thing goes good.
    i have doubt, how to create transaction code for maintenance view. I created view for tranperant table and now i want to create transaction code for the view.
    i tried and i donot know the screen number and program name and where can i give the view name.
    if any one know please post in details.
    thanks in advance.

    Hi Elam,
    You need to create a "Parameter Transaction".
    What this means is that you will have a transaction (let's call it "ZMAINT") which calls "SM30" and passes in your table name.
    Go to transaction SE93 and enter your new transaction code. Enter in the Tcode description and choose "Transaction with Parameters" (it shouldbe the last radio button).
    Enter in the default transaction "SM30" and tick the "Skip Initial Screen" check box. Hit Enter.
    Now scroll to the bottom of the screen and you will see a Table Control where you will need to enter in the values to the SM30 selection screen.
    Because you hit ENTER, the program will have loaded in the Selection Screen parameters into it's memory. Hit the drop down for "Name of Screen Field" and select "VIEWNAME" and then enter in your Z Table in the "Value" column.
    Now go to the next line and hit the drop down and select "UPDATE" in the "Name of Screen Field". Enter in a "X" in the value column.
    Now save the transaction and there you have it.
    Hope this helps.
    Cheers,
    Pat.
    PS. Kindly assign Reward Points to the posts you find helpful.

  • How to write a code for  open new txt file in swing

    hai all,
    now i do one project in java.that project's GUI is Swing. But i don't known swing (basic).So how to write a code for open new txt file and "Open window " in menu item on swing.that means when i click the "New" on menu that time open a new txt file. open also like that type.
    plz give me that code ! very urgent
    Advance Thanks !
    RSK

    Swing Tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    Since you don't know the basic of swing read the tutorial, it is for your own good because it is useless if we provide you with a code you don't even understand and how it works.
    If you want a menu read the tutorial about using menus and for opening a file read using JFileChooser.
    note: don't use the word urgent because it implies that your problem is more important than others.

  • How to consolidate the financial statements for 3 company codes, assigned t

    Hi Friends,
    How to consolidate the financial statements for 3 company codes, assigned to 3 different companies, 3 different fiscal years, 3 different controlling areas and all the 3 Company Codes assigned to same chart of accounts in the same client?
    Can we need any ABAP program for this (or) Is it possible using Report Painter?
    Please help me.
    Thanks

    Hi friend,
    Is it a real-time situation or something you are visualising ?
    For consolidation, you can use a group chart of accounts and select that in the operative chart of accounts for consolidation purposes.  This would work provided the company codes use the same operative chart of accounts and fiscal year.
    I hope the above would be helpful to you.
    Regards,

  • How to create Transaction code for ABAP and execution by other user

    Hi All,
    Could someone please let me know how to create transaction code in detail for ABAP program. Step by step procedure expected. I would like to know how other user can execute the report using same transaction code which I have created.
    More about authorization.
    Thanks in advance.

    Hello,
    You can create transaction code from se80 as well.In object navigator,right click on your program name and create->transaction code.You can create transaction and select if it is only a report,a report with selection-screen depending on your requirement.You can run your report directly by entering the transaction code in the command field.
    You can authorise the users who can use your transaction:
    <b>Authorisation objects</b> are used to restrict certain transactions to users.Critical data must be protected from unauthorised users.For example,the head has access to certain data.But it cannot be accessed by his subordinate.For this we need to define <b>roles</b>.
    •Create an authorization object with transaction SU21.
    An object usually consists of the ACTVT (activity) field and one other field,which specifies the data type to be protected.By ACTVT, we can decide if the data is accessible for change,display only etc.
    •Add authorization fields to the authorization object created.
    •Assign the authorization object to the transaction using SE93.
    Attach the authorization object to the role using transaction PFCG.
    If you want <b>to assign roles</b>,use transaction PFCG.Create a new role.In the AUTHORIZATIONS tab,you can get a self generated profile name and a profile text by clicking on the icon next to it.Then go to the "Change Authorization data" and choose an authorization template.Then you can choose to display/change/create an activity and after the selection,click on the red and white circle.The profile will now be created.
    In the user tab,you can give the user details who can use this role.
    <b>Also check this link:</b>
    http://www.*********************/r3_security/r3_security_tips.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/52/6716a6439b11d1896f0000e8322d00/content.htm
    <b>Very helpful guide:</b>
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a92195a9-0b01-0010-909c-f330ea4a585c
    Regards,
    Beejal
    **Reward if answer is helpful

  • How to create transactoin code for a predefined variant?

    Hi,  I have created one variant for a custom report.How to create transaction code for the report with that variant?

    When you create the transaction in SE93 select the Program and selection screen(Report transaction) type not
    the transaction with variant(Variant transaction)

  • Instruction on how to enter unlock code for AT&T 6...

    Hello everyone,
    I got a little issue, hopefully someone in here can help me out.  Thanks in advance!
    I have a Nokia 6650 locked to at&t network but I requested the code from them and they provided the code and the instructions on how to unlock it.  I follow all the steps carefully inputting the code but after I am done and it says NOT ALLOWED.  I wonder if this means I have the wrong code or the instructions are wrong, below are what they provided on how to unlcok:
    #pw+code+1#
    Does this instructions works on all Nokia phones or not the 3G?

    Hi fairview 
    Unfortunately it is not unknown for network provider to give out incorrect code but your code should be in similar format to this as you mention:
    #pw+000000000000000+1#
    You use repeated "*" presses to obtain "pw+", allowing about a second between repeated presses; once you have mastered it the first time there is no problem.
    Note that there are only limited attempts at inputting this code before you are locked out. 
    Happy to have helped forum in a small way with a Support Ratio = 37.0

  • How can i change the phonenumber for my security code in keychain on ios 7.03

    how can i change the phonenumber for my security code in keychain on ios 7.03?

    i have changed the phonenumber under icloud preferences keychain. after the update on ios 7.03 there is no sms arriving for the security code because there is a double international code in the telephone number like +49 +49. How can i fix this?

  • How to create plsql code for a snowflake cube

    hi everybody!
    do anyone know how to create plsql code for a snowflake tiype dimension to create
    a cube?how to map the atributes, or if there are any exceptional atributes which I can use like in a temporal dimension?
    thank you
    waiting for any answer

    The DBMS_AWM package provides stored procedures for creating an analytic workspace cube from a star schema. Is it posible to create a cube from a snoflake schema?

Maybe you are looking for

  • Issue with SQL%BULK_EXCEPTIONS.COUNT in Oracle 9iR2

    Hi All, We are using the Oracle 9i Database Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production PL/SQL Release 9.2.0.7.0 - Production CORE 9.2.0.7.0 Production TNS for HPUX: Version 9.2.0.7.0 - Production NLSRTL Version 9.2.0.7.0 - Produ

  • Rescue Query name

    Dear all, I need to rescue the names of every Query in my page dynamically. I'd like to use it in every my page to check the Query ExecutionTime. How can I rescue the query name? thanks in advance Best regards

  • Prereq packages for grid 11.2.0.3 on rhel6

    I am trying to install grid infrastructure 11.2.0.3 on rhel6 x86_64 and I ran the runcluvfy.sh script with the following options and it is reporting that there are a handful of missing packages but when I try to use yum to download and install the pa

  • Problems in customization Oracle AS Portal

    How I can rewrite forms to edit, create ,grant to users and group of users ? How Oracle AS Portal interacts with Single Sign-on(SSO) ? Which protocol or API is used ? Thanks in Advance . FSS

  • Maximum number of members in a dimension in ASO 11.1.2.1

    Hi all, Is there any limitations on number of members in a dimension in ASO 11.1.2.1? Also can we predict the maximum number from the 64 bit theory as described in the DBAG? I guess the maximum must be more than 20 million which I believe was the lim