Foreach equivalent in java

Hi all,
I am doing some conversion process from C# to java. I am struck with c# foreach statement.
Here I give the coding,
foreach (MapFieldInfo item in Fields)
if (item == null)
continue;
if (item.Field.Equals(fieldInfo))
exp = item.NewExpression;
break;
Here the MapFieldInfo in another class. I need the equivalent java for loop for this statement.
Pls could anyone help me.
Thanks in advance.
Uma

for (Iterator it = aCollection.getIterator(); it.hasNext();){
  MyClass myObj = (MyClass)it.next();
  // .. do stuff with myObj
}I understand that the J2SE 1.5 spec is going to add something similar to foreach to the Java language - it's really just syntactic sugar to make the code a little less verbose, though.
Also, you just know that there are going to be people using the new nomenclature that forget what an iterator is altogether and make silly programming decisions...
- K

Similar Messages

  • Equivalent of java.sql.ResultSetMetaData

    Hi,
    I'm looking for something which is equivalent to java.sql.ResultSetMetaData in Toplink. Does anyone know how this can be done ?
    Thanks,
    -Prashant

    Hi,
    I have a similar problem. I want to find out the column names when i fire raw-sql. I use SQLCall to do this.
    Then I get a Vector<DatabaseRow>.
    Vector vDR = session.executeQuery( new SQLCall( "select * from table_name" ) )
    Now Is there a way to find out the column names dynamically. In the javadocs i see that objDatabaseRow.keys() returns an Enum<DatabaseField>... but i cant see javadocs on how to use DatabaseField.
    So is there any other way ?
    Thanks,
    Krishna

  • Can we define a complex type that is equivalent to java.util.List?

    hi everyone
    is it possible to define a complexType that is equivalent to java.util.List? all i know now is how to define an array of some type using either <xs:list> for simpleType or the minOccurs and maxOccurs of the element tag. i was wondering if there is way to define something equivalent to a List in java. thanks

    Define a sequence of list tems.
    <xs:element name="list">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="item"  maxOccurs="unbounded"  type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>

  • ReDim equivalent in Java

    Hello,
    What's the equivalent in Java of 'Redim '?
    e.g Redim RedBucket(0)(0)
    is it an ArrayList
    Thanks
    Paul

    ReDim is like ArrayList in the same way that a wheelbarrow is like a pickup truck.
    With ReDim, you have to specify the size of the array at the beginning, and then you have to decide when the size needs to be changed, and you have to decide what to change it to. With ArrayList, you don't have to do any of that. You just say "Gimme an ArrayList" and it figures out how much array space it needs by itself.
    But really, you're better off just learning Java. You won't want to speak Java with a VB accent.

  • APEX equivalent of Java Static Initialization Block

    Is there a APEX equivalent of Java static init block (i.e. execute once at class load time)? My use case is that I need to load some configuration values to an environment (i.e. APEX Workspace) specific variables and don't want to do per user session since the values remain the same for all user sessions. I believe SYS_CONTEXT is tied to user session and would not be useful for my usecase. Any advise would be appreciated.

    Hello,
    You should check the concept of User Preferences and see if it can help you:
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21678/aadm_mg_sessions.htm#BABHFEFD
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • $ENV perl equivalent in Java

    We are in our first steps in trying to convert some of our systems from Perl to Java.
    In a module we had (Database module) which was responsible for all DB activity, we had an area where, upon errors, we printed out $ENV{SCRIPT_NAME} environment variable, which is set by Apache and can be read by Perl. This helps us debug things by knowing which script was ran when a DB error occurred.
    As we are porting the Database module into a Database class, we are trying to think how we can achieve the same capability with Java.
    I don't know of the existence of $ENV equivalent in Java. Not one that contains the web-server executed script, in case its a script that is ran by a web server.
    Is there?
    Note that the Database module may be ran as part of a Servelet but may also be part of just a simple server script. In perl, is such case, the $ENV{SCRIPT_NAME} would come out empty.
    Any suggestions of how to do that?

    Pidgin wrote:
    As you indicated: Note that both are relatively slow and should only be used for exceptional or error conditions.
    The access to the SCRIPT_NAME is actually a web re,ated variable that we need for showing which HTTP resquest generated the specific SQL error.It's only a variable in perl (or in CGI scripts, to be more precise).
    It happens often enough, and doing a very low-level trace of the executed code migt not be the right option.SQLExceptions that need logging happen often? That shouldn't be the fact. How often?
    Stacktraces are not awfully slow. They are ok for handling errors & exceptions. But they should not be used for classical flow control.
    For example, it might be that the executing code is Script.class using Database.class, but Script.class can be initiated from www.whatever.com/script/ or www.whatever.com/premium/script/.. in each case, we want to know the full URL of the called "script'.With the stack trace you'd see the Servlet and/or Action that handles the request.
    So we do need access to the web "environment".
    What we do now, is store a static Servlet_Request variable (set on the first Database constructor, by passing the servlet request and response objects to the Database constructor). From that point on, we can access Servlet_Request.getRequestURI()That won't work as soon as more than one request is handled at the same time (which is very, very soon!).
    You might want to look into something like log4js MDC, where you can at one point in your application set a key in a map and have that appear in every log statement from that thread until it's removed again.
    This is quite different than the Perl logic, where we could access a "web enabled" System.getenv() and read from it SCRIPT_NAME or other web related parameters, if they existed (or returning null if they didn't)You should not try to apply the best practices learned by perl web programming 1:1 on Java. In the Java world pretty different concepts apply, especially when doing Web-Programming, as Perl web-applications are usually based on the rather antiquated CGI interface, while Java uses a central application server that handles each request as it wishes.

  • Forte Express Equivalent in Java

    Hi
    Can any body tell me Forte Express equivalent in Java?
    Thanks in advance

    Hi
    Can any body tell me Forte Express equivalent in Java?
    Thanks in advance

  • Struct equivalent for java array?

    What's the struct (c++) equivalent in Java?
    here's my im doing.
    class Text
    char character;
    int freq;
    public static void main(String[] args) throws IOException
    BufferedReader key = new BufferedReader(new InputStreamReader(System.in));
    Text[] letter = new Text[2];
    I want to assgined letter[0].character = 'a'; and letter[0].freq = '3' but it doesn't allow me to do that when I compile it?

    I've trying doing:
    for(i = 0; i < letter.length; i++)
                   letter.character = new Text();
                   letter[i].freq = new Text();
    and even
    for(i = 0; i < letter.length; i++)
                   letter= new Text();
    before doing
    letter[0].character = 'a';
              letter[0].freq = '3'; but got an error:
    non static varible this cannot be referenced from a static context

  • Hash() in coldfusion equivalent in java

    Hi,
    I have a hash function in coldfusion which i want to implement in java. The coldfusion hash function in my case DOES NOT take any algorithm as a parameter. In java I have seen that to use message digest we have to specify an algorithm. Can it be done without any algorithm specified ?
    Here is the documentation of the coldfusion hash() function:
    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000503.htm#1105551
    Thanks

    theLeonidas wrote:
    I have a hash function in coldfusion which i want to implement in java. The coldfusion hash function in my case DOES NOT take any algorithm as a parameter. Then you need to find out which algorithm is used for your function.
    In java I have seen that to use message digest we have to specify an algorithm.
    Can it be done without any algorithm specified ?Just because you don't need to specify one in 'cold fusion' does not mean that one of the standard algorithms is not being used. It should be easy enough to find out which one is being used - in Java, just try all those listed in the document you referenced below and compare the result with your coldfusion result.
    >
    Here is the documentation of the coldfusion hash() function:
    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000503.htm#1105551
    P.S. I bet your function uses the MD5 hash.

  • Realtime equivalent to Java's Thread.sleep()?

    I have an application that I want to guarantee that when I call Java's Thread.sleep(n) the thread will sleep for precisely that amount of time, or close to it at least. What we recently encountered though was that if the "wall clock" time is changed in one thread while a sleep is occurring in another thread, this clock change will impact when the sleeping thread will wake up.
    In our case, we had a simple Thread.sleep(1000), and during that one second period another thread set the clock back two minutes. The sleeping thread ended up sleeping roughly two minutes and a second instead of just a second. Apparently this is a "feature" of Thread.sleep(), and I can see in some cases (e.g. a task scheduler based on wall clock times) where this is exactly the behavior you'd want. However, in our case, we want the sleep function to sleep by the amount we specify, regardless of changes to the wall clock time. Is there a way to do this in Java? We are using JDK 1.5.

    You can use methods which rely on the nanoTime() (based on the number of clock cycles since the processor last reset)
    Classes such as LockSupport.parkUntil(someObject, nanoTime) may give you the accuracy/consistency you want. In this case you always wait the full delay.(and not unpack it)

  • Md5sum equivalent in java

    Hi,
    md5sum on solaris produces "9b9af6945c95f1aa302a61acf75c9bd6" for the string "abcde".
    But when I tried using the following sample code,
    MessagDigest md = MessageDigest.getInstance("MD5");
    String str = "abcde";
    byte[] bytes = md.digest(str.getBytes());
    StringBuffer hexString = new StringBuffer();
    for (int i=0;i<bytes.length;i++) {
    hexString.append(Integer.toHexString(0xFF & bytes));
    System.out.println(hexString.toString());
    This prints "ab56b4d92b40713acc5af89985d4b786".
    Why Java implementation of MD5 is different from md5sum of solaris. How can I achieve the same result.
    Thanks,
    Sreedhar.

    I have the answer now:
    I guess you got the md5sum on Solaris by typing the "abcde" into a file and running md5sum on the text file, right? Well, if you check the size of the file, you will see that it occupies 6 bytes and not 5, right? Well that's because it also contains the EOF (End Of File) byte, right after the text. So if you run md5sum on the file, it will include the EOF.
    Change your code to use the string "abc" instead of "abcde". This will return the digest string "90150983cd24fb0d6963f7d28e17f72". Then take a look at the reference digest for the string "abc" in the MD5 RFC http://www.ietf.org/rfc/rfc1321.txt at the bottom of the file. It says 900150983cd24fb0d6963f7d28e17f72. That's almost the same. The error in your code is that Integer.toHexString(0xFF & bytes) will return the string "1" for the byte with the value of 1, but should return "01".
    Change
    for (int i=0;i<bytes.length;i++) {
         hexString.append(Integer.toHexString(0xFF & bytes));
    to
    for (int i=0;i<bytes.length;i++) {
         String digit = Integer.toHexString(0xFF & bytes);
         if (digit.length() == 1) {
              digit = "0" + digit;
         hexString.append(digit);
    Then you will have a fully correct implementation of the MD5 digest.

  • What is MFC sendMessage/postMessage equivalent in java?

    Hi, i am new to java. i hope i can get some help from u.
    question #1. how does user defined message work in java?
    question #2. how to send a message from dialog1 to dialog2 message quene and how to capture this message?
    thank you very much
    --mila                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I am not aware of what "messages" do in MFC. Do they transmit some form of information from one component to another? Please enlighten me; I may be able to help you then.

  • Python equivalent of Java 'setchar'

    so a user can enter something from standard in and echo back *'s or nothing at all instead of printing to the screen their actuall input. Like entering your password when you login.

    Will the getpass module work for you?
    >>> import getpass
    >>> getpass.getpass()
    Password:
    'Secr3t'
    >>> getpass.getpass("Enter your password : ")
    Enter your password :
    'Secr3t'
    >>>

  • Java Equivalent to Get ForegroundWindow?

    MSWindows native programming has a call named GetForegroundWindow(). This call returns the handle to an application window that currenlty is active (sometimes also termed as "has focus"). I'm looking for something equivalent in Java.
    Note that any method that gets the name of the application (such as MSWord), and the file that is being processed (such as Document1.doc) will do.
    It would also be nice to find a method of being notified by MSWindows when the foreground window changes.
    And, finally, having this workable in both Linux and MSWindows would be great - even if the methods are different for the two operating systems.

    Note that any method that gets the name of the
    application (such as MSWord), and the file that is
    being processed (such as Document1.doc) will do.Did you notice the word "native" you used earlier? Java wouldn't know about other processes and their windows, and most certainly not in a system-independant way.

  • Communication between java and c++, help!

    i am c++ programmer and newly to java.
    now i am developping a client/server app. i use java transfers data (socket) between client and server, and use c++ to create user interfaces because c++ is easier for interfaces.
    my question is:
    in a single PC, java needs to tell c++ what info was read from socket and c++ needs to tell java what info will be written to socket.
    i want to use 2 files (read and write) as media between java and c++. that is: java writes data to a file and c++ reads from the file, and vice versa.
    i know it's not efficient. could you tell me better way to do?
    thanks in advance.

    thanks for reply.
    my problem is: socket is fare in java, not fare in c++
    (win/nt). could u use server in a non nt-server
    machine with c++?I'm not sure what you mean "fair". NT-Server is just a version of NT that Microsoft adds their server products to. Most of which you don't want to use because they are a security nightmare. I think what your asking is can you do the equivalent of Java's ServerSocket in C++. Sure, the socket libraries in Windows (at least last time I checked) were based off the BSD socket libraries. So you would basically do something like:
    // Open socket
    ss=socket(AF_INET, SOCK_STREAM, 0);
    if(ss==-1)
      cerr<<"Error opening socket."<<endl;
      return 0;
    // Fill in address
    struct sockaddr_in server;
    server.sin_family=AF_INET;
    server.sin_port=htons((unsigned short)port);
    server.sin_addr.s_addr=INADDR_ANY;
    // Bind to port
    if(bind(ss, (struct sockaddr *)&server, sizeof(server))==-1)
      cerr<<"Could not bind to port "<<port<<"."<<endl;
      return 0;
    // Ready to accept connections
    if(listen(ss, 5)==-1)
      cerr<<"Could not listen."<<endl;
      return 0;
    // Loop to accept connections
    while(/* some condition */)
      // Accept a connection
      int s=accept(ss, 0, 0);
    }This should work on any version of windows as long as you have winsock. The example code might need to be changed a little though since I copied it from a Linux program I had.

Maybe you are looking for