Custom List with for-each loop

How do I get a list I am making to be able to be used with a for-each loop?

As far as I know there is no "for-each" loop in Java, there is however a "for" loop. Is that what you're referring to?
To use a for loop, let's say you have an array like the following, you could iterate through it like this:
String[] str = new String[]{"a", "b", "c", "d", "e"};
for (int i = 0; i < str.length; i++)
         System.out.println(str);
hope this help you get started ;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Facing issue with for each loop in excel VBA

    Hi,
    I am using VBA .
    I am looping through each row and the column matches value,I am getting the value of  G column with the selected row.
          Dim selectedCell As Range
            Dim weekMinutes As Double
            Dim rowNumber As Integer
            usageTracking.Activate
            weeklySheetName = sheetName
             For Each selectedCell In ActiveSheet.Range("A:A")
              If selectedCell.Value = customerName Then
        '          weekMinutes = ActiveSheet.Range("G" & (selectedCell.row)).Value
                   weekMinutes = Cells(selectedCell.row, "G").Value
        End If
          Next selectedCell
    I am able to get value for the first row.
    from second row,even though i am having different value,the "weekMinutes" value is showing as 0 instead of the value in the cell.
    whats wrong I am doing.

    Hi AjayChigurupati,
    The code seems ok, and I also made a quick test. It works well for me.
    Please check the value in A column, the weekMinutes variable only was assigned when the value in column A is equal customerName.
    I also suggest that you loop the UsedRange in Column A to improve the preformance.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Issue with Reading data with FOR EACH LOOP.

    Hi Guys,
    Scenario
    We Plan Sales of an Article on a half years(fiscal variant MQ with 2 periods of half year each). We also plan the
    number of Weeks in Sales as a Key figure.  The cummulative Sales for two half years in then distributed to number of weeks for which the Article is sold (0CALWEEK)
    In another Cube we plan a distribution profile. This cube contains just three elements.
    Characteristic = ZPROFILE
    TIme Char = 0CALWEEK
    Keyfigure = ZDIST
    (Note : You will notice The distribution profile is not stored per Article here)
    The logic of distribution is :
    1.  Sales of Article is cummulated for 1 years ( eg. for periods 001.2010 & 002.2010 )
    2.  Find the number of weeks in Sales for this Article ( eg. 14 weeks. ) [Technically we store this value on the first fiscal
    period. In our example it is stored in 001.2010
    3.  User choose a distribution profile in a variable ( e.g ZH55 )
    4   ZDIST is summed for number of Sale Weeks for this Article. in our case it is14 weeks.
    5. Distribution = Sales of Article (WEEK N) = [Sales Cummulated for 1 year] * [ZDIST(Week N) / ZDIST(sum of 24 weeks)]
    This loop is run 14 times. (N from 201001 to 201014.)
    TECHICAL DETAILS
    Cube 1 (0CM_SKU = Material, 0CPBAINSABU = SALES key figure, WEEKINSALE = Number of weeks for which Material will be
    sold). The Sales Planned data is stored as # for 0CALWEEK.
    0CM_SKU/0CALWEEK/0FISCPER/0FISCVARNT/0CPBAINSABU--/WEEKINSALE
    SHIRT/000000/2010001/ZP/100EUR--/24
    SHIRT/000000/2010002/ZP/200EUR--/00
    PANTS/000000/2010001/ZP/300EUR--/35
    PANTS/000000/2010002/ZP/200EUR--/00
    CUBE 2 ( the profile data is stored here )
    ZPROFILE/0CALWEEK/ZDIST
    ZH55/201001/10
    ZH55/201002/12
    ZH55/201003/8
    ZH55/201004/11
    ZH55/201005/10
    ..so on.
    9:11 PM
    Edited by: Dheeraj Gupta on Apr 5, 2010 9:20 PM

    My Sample CODE IS BELOW.
    DATA CW1 TYPE 0CALWEEK.
    DATA CW2 TYPE 0CALWEEK.
    DATA PER1 TYPE 0FISCPER.
    DATA PER2 TYPE 0FISCPER.
    DATA FVAR TYPE 0FISCVARNT.
    DATA PROV1 TYPE 0INFOPROV.
    DATA PROV2 TYPE 0INFOPROV.
    DATA SKU TYPE 0CM_SKU.
    DATA DPROF TYPE ZPROFILE.
    DATA CUMSALES TYPE F.
    DATA TEMP TYPE F.
    DATA PRO TYPE F.
    DATA COUNT TYPE I.
    *I WILL READ THE PROFILE VALUE FROM VARIABLE IN ACTUAL PROGRAM.
    HARDCODED FOR TEST PURPOSES. 
    DPROF = 'ZH55'.
    *FISCAL YR VARIANT
    FVAR = 'MQ'.
    *HARDCODED FOR TEST PURPOSES. 
    PER1 = 2010001.
    PER2 = TMVL(PER1, 1, FVAR).
    *CUBE FOR SALES
    PROV1 = 'ZCLARK'.
    *CUBE FOR PROFILE
    PROV2 = 'C_ZCLARK'.
    FOREACH SKU.
    *SUM UP SALES FOR ONE YEAR
    *Operand:{Key figure name, 0CALWEEK, 0CM_SKU, 0FISCPER, 0FISCVARNT, 0INFOPROV, ZPROFILE}
    CUMSALES = CUMSALES + {0CPBAINSABU,#,SKU,PER1, FVAR,PROV1,#} + {0CPBAINSABU,#,SKU,PER2, FVAR,PROV1,#}.
    *READ NUMBER OF WEEKS OF SALES
    COUNT = {ZNWEEK,#,SKU,PER1, FVAR,PROV1,#}.
    *HARDCODED FOR TEST PURPOSES. 
    Starting week of distrbution is first week of the year
    CW2 = 201001.
    CW1 = 201001.
    *HELP NEEDED HERE ***********
    *NOT ABLE TO READ THIS PROFILE DATA
    DO COUNT TIMES.
       PRO = PRO + {ZPROF,CW2,#,#,#,PROV2,ZPROFILE}.
       CW2 = TMVL(CW2, 1).
    ENDDO.
    DO COUNT TIMES.
    {0CPBAINSABU,CW1,SKU,#, #,PROV1,#} = CUMSALES * {ZPROF,CW1,#,#, #,PROV2,ZPROFILE} / PRO.
    CW1 = TMVL(CW1, 1).
    ENDDO.
    *RESET
    CUMSALES = 0.
    ENDFOR.

  • SQL Agent Permssions With SSIS for each loop not looping through files

    Hi I am Having trouble getting a ssis package to iterate through a file directory using a proxy account set up in Sql Server.
    So I have a package that loops over csv files. If I run the package manually or set the sql agent job to run as Sysadmin the pakage runs fine all files are processed.
    However if I use the proxy account. the package completes but no files are processed. there are no failures, there is no error handling set up in the control flow. the for each loop container simply does not recognise any files when run under a proxy.
    Note: the proxy is set up with credentials to access the folder. the credential is also set up with the server admin server role... still nothing
    i'm not sure is this is a ssis or permissions problem?
    Any comments will be appreciated

    Can you check this and see if you've configured all the steps correctly
    http://www.mssqltips.com/sqlservertip/2163/running-a-ssis-package-from-sql-server-agent-using-a-proxy-account/
    Also enable logging in package and see if you're getting any error messages obtained in output table/file based on the logging option you chose.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Single row table with for-each group loop to set variable.

    Hi: There is probably a simple answer for this but I have not found it ...
    I have a single row table to loop through a group to set a variable holding a running amount. I am not displaying the amount within the table however when I preview the report I see that the table is expanding (adding rows) for each loop.
    The single row table has 3 columns.
    1st column
    <?for-each:AC_GROUP?>
    2nd column
    <?xdoxslt:set_variable($_XDOCTX,'xAmtVar',xdoxslt:get_variable($_XDOCTX,'xAmtVar')+CURRENT_AMOUNT)?>
    3rd column
    <?end for-each?>
    Should I be using <?for each-group?> or something else. My requirement is to set the value of the variable with the running total but because the loop is adding rows for each value it loops through (even though not displayed), it is moving other areas of the layout off the page.
    Hope this makes sense. Thanks in advance.

    you can do it many ways.
    No need to loop
    You can create a variable and put the sum amount directly in that.
    <?doxslt:get_variable($_XDOCTX,'xAmtVar',sum(/AC_GROUP/CURRENT_AMOUNT))?>or
    loop thru and add like you do.
    <?for-each@inlines:AC_GROUP?><?xdoxslt:set_variable($_XDOCTX,'xAmtVar',xdoxslt:get_variable($_XDOCTX,'xAmtVar')+CURRENT_AMOUNT)?><?end for-each?>do give any space or enter character in word between them, just put this in a single form-field will do
    But as i said, i would certainly go with first option.

  • For each loop with multidimensional arrays?

    Hi.I have a problem with for each and multidimensional combination.
    public class TestCards
    static int[][] dizi={{1,2},{3,4}};
    static int t ;
    public static void main(String[]args)
         for (int[] i : dizi)
         System.out.println(i);
    The result of the codes above is like this
    [I@9304b1
    [I@190d11
    In other words the result is now integer.It has some strange chars which i dont know
    Pls help me !

    You're printing an array. Arrays don't override toString.
    - You could iterate over both dimensions and print each value yourself.
    - You could iterate over one dimension and call java.util.Arrays.toString to print a row at a time.*
    - You could call java.util.Arrays.deepToString to print the entire thing in one shot.
    *The second option is closest to what you're doing now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • For each loop and modification of a LinkedList

    When going thourhg my LinkedList with a for each loop, I want to do a modification. I just saw that it cast a ConcurrentModification Exception, so it seems I can't do that.
    How should I do then? I don't want to go through all the list each time an object is removed, I want it to restart where it stopped.

    Not the best solution but something like thisshould work:
    if( linkedList.get(i) == "modification")No: don't compare Strings with the == operator.
    http://access1.sun.com/FAQSets/newtojavatechfaq.html#9
    You are correct, must be .equals() my bad.

  • Need to access parent elements in nested for-each loop

    Hi All,
    I have a xslt mapping requirement in which I am completely stuck. The details are as listed below. Please help!
    Schema structure is as follows:
    Root
    Payload
    Transaction-123
    Loop-LINE
    Loop-SDPP
    Segment-FSTT
    Element-111
    Required xslt file structure is:
    <xsl:for-each Loop-LINE>
    <tns:Item>
    <Line-1000>
    <Line-2000>
    <Line-3000>
    <Line-8000>
    <xsl:for-each Loop-SDPP>
    <xsl:for-each Segment-FSTT[ns0:Element-111 != "A"]>
    <SDetails>
    </SDetails>
    <xsl:for-each Loop-LINE> --------- How to access Loop-LINE element from this for loop????
    <tns:Item>
    <2000>
    <2020>
    <2070>
    <2150>
    </tns:Item>
    </xsl:for-each>
    </for-each>
    </for-each>
    </tns:item>
    </for-each>
    Need help in understanding how can I run a for-each loop for Loop-LINE which is two levels up in the schema tree structure.
    Thanks..

    Thanks for this answer but I can't obtain the right output with my test case; the multi column must be in the loop as that :
    ALPHABETICAL INDEX C1
    Alternator .......................................... Feed Pump
    Belt Details / Engine Gaskets Sets ..... Flywheel Housing
    < NEW PAGE>
    INDEX ALPHABETIQUE C2
    Alternateur......................................... Culbuteurs
    Bloc-Cylindres.................................... Demarreur
    Denis

  • How to use for each loop in XSLT when my source is a multilayout file and db

    How do I use a for each loop in XSLT when my source is multilayout file and db .
    My multilayout file is basically contain 2 kind of data one for employee and another for dependent.
    Now my requirement is I want to read each line of data whether it is it is employee or dependent do a join with db and write it in my target file.
    eg :  File content
    1 RichaKumari 311289 TCS INDIA
    2 KiarnKumar 456782 BRO RichaKumari 311289 INDIA
    2 Ravi            456882 BRO RichaKumari 311289 INDIA
    eg : db Content
    311289 RichaKumari TCS INDIA Bangalore [email protected]
    Now in Final File I need something like this :
    1 RichaKumari 311289 TCS INDIA
    2 KiarnKumar RichaKumari 311289 TCS INDIA
    2 Ravi            RichaKumari 311289 TCS INDIA
    here 1 and 2 are the identifier which will decide which layout to follow .

    Hi,
    I think you'll need two nested for-each's... Something like...
    <xsl:for-each select="$root/row[layout = 1]">
    <xsl:variable name="employee" select="."/>
    ... write employee ...
    <xsl:for-each select="$root/row[layout = 2 and dependentid = $employee/id]">
    ... write dependent ...
    </xsl:for-each>
    </xsl:for-each>
    Cheers,
    Vlad

  • Loading accdb file using for each loop in to single target table

    I have 3 accdb file as below in single folder, in control flow I have created a for each loop to loop through all the below file.  In dataflow task I have created oledb source using connection manager to point to first file a1.accdb. I am trying
    to load all the file into single below mentioned target table, here It is only loading first file it is not looping through other two file.
    This I have tried to load .txt files and csv files it is working perfectly but similarly when I try to load access db file table it is not working, can any one of you help me?
    1. a1.accdb contains only one table  a1tab ( col1 col2 col3 )  
    2. a2.accdb  contains only one table  a2tab  ( col1 col2 col3 )
    3. a3.accdb  contains only one table  a3tab   ( col1 col2 col3 )
    I have a target table with similar structure as source
    Target table <TargetTable> Col1 Col2 Col3
    aak

    Thanks Arthur, please find below response
    How do you handle the different table names?  Cant we handle it in a similar manner, how we handle the .csv/.txt files with different name and similar structure for sources(multiple files) and target (single table)
    Is it good to drop the idea of for each loop and create a separate task for each accdb file? to be loaded to same target table( performance wise etc.. any justification would be helpful)
    You must handle the connection string dynamically?
    Can you help me with the logic for handling connection string dynamically
    aak

  • How can I enable for-each loop in Creator update 1?

    I try to use for-each loop, but I got error message from compiler is
    " for-each loops are not supported in -source 1.4. (try -source 1.5 to enable for-each loops)"
    How can I switch my source to 1.5.. I am using jdk 1.5. Confusing.
    Thanks .
    Richard

    Hi!
    Actually Sun Java Studio Creator doesn't support Java EE 5 projects. If You want to create Java EE 5 project, try to use NetBeans with Visual Web Pack installed.
    Thanks,
    Roman.

  • For Each Loop in Jdev 10.1.2.17.84

    Is there anyway of using a for each loop in Jdev 10.1.2.17.84? I get errors for the standard syntax:
    for (int item : numbers) {
    System.out.println("Count is: " + item); }
    Am i missing something?

    Okay, i'm on 10.1.3 now and the syntax:
    for (int item : numbers) {
    System.out.println("Count is: " + item); }
    still doesn't work. What am I missing now?
    On compile I'm getting:
    Error(41,23): ; expected
    for the line with for (int item : numbers) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • For each loop not working

    My trace statements inside my for each loop won't show.
    Please someone check my code. I"m getting no errors in flex
    builder. When i debug all vars are holding prober data. Thanks so
    much

    "essa tkinen" <[email protected]> wrote in
    message
    news:gr27rt$3sb$[email protected]..
    > yes there is data there a commas delimited list of
    keywords that are
    > catagorys. the selectedCatArray holds at list one
    element. I want to
    > return true if element is in that list
    For one thing, you're going to exit the function in the first
    iteration,
    because you return the result inside the loop. Return
    immediately exits the
    function. For another, I'd be tempted to switch it to
    something more like
    this:
    for (var i = 0; i<_item.cats.length; i++) {
    var iCat=item.cats
    //do your stuff here
    I have had really bad luck getting for each in to work the
    way I think it
    should.
    HTH;
    Amy

  • For Each Loop for XML Task

    Hello Everyone,
    Please assist with a step by step guide on how to setup a For Each Loop for XML Task
    I'm trying to convert XML to XSLT
    I have tried more than 10 times and i just do not know what i am doing wrong - no error, my package just runs for a few seconds but nothing happens
    Thanks in advance
    Dee

    I managed to get my XML to XSLT to work but now when i run my package to import the data into SQL table,
    it stops after a few records, i get the following error: 
    [XML Source [1]] Error: The component "XML Source" (1) was unable to process the XML data. The element "Errors" cannot contain a child element. Content model is text only.
    Please assist
    Check this:
    http://social.msdn.microsoft.com/Forums/en-US/80726e0c-9e85-43ca-87bc-7cf90fd7fb31/xml-source-data-flow-throws-cannot-contain-a-child-element-content-model-is-text-only-error?forum=sqlintegrationservices
    Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real.
    The climb is all there is.

  • For Each Loop - Urgent

    Hi,
    I am trying to use a For each loop:
    FE Agreement_No
    Customer
    0.00
    0.00<?end for-each?>
    This does not work. Does the code FE need to be grouped?
    Can anyone help?
    Thanks

    Hi,
    I have created a repeating group:
    <?for-each-group:ROW;./Agreement_No?>
    This places an F in front of agreement_no field
    and places E in front of the following field customer.
    I would also like to add a condition where installment = 'Under 1'
    Would that be <?for-each-group:ROW;./Agreement_No[../Installments='Under 1']?>

Maybe you are looking for

  • IBook hard drive errors

    My brother's iBook G4 12" started freezing randomly, and when I tried to run disk utility it would give me lots and lots of errors. Apple Hardware Test spit some errors which I don't remember (unfortunately), and then the hard drive stopped showing u

  • Changing the owners name...

    hey, just a little thing but is kinda annoying, anyone know how to change the name the ipod is registered to...u know when the ipod is updating in itunes it says "name Ipod"....

  • Having issues connecting to internet after CenturyLink fiasco

    After the CenturyLink nationwide internet outage, my mac mini will connect to internet, but the thing is that I will start an internet browser, it will sit there for about five minutes looking up the site, then it'll tell me that it won't connect. Tr

  • Replacing iMac Hard Drive

    My existing hard drive is nearing its maximum capacity, and I want to replace it with a newer, larger hard drive. I have a 450MHz Indigo iMac G3 running OS X Tiger. In all other respects, the system is working beautifully. Anyone have suggestions for

  • Aperture 3 How do I password protect my library/folders!? Tried everything but also no good at this type of thing!! ty

    I have looked at previous posts but can not find a way of password protectin an entire folder. I have photos on my Macbook that I dont want my 7 year old to see. If necessary I will move my photos (if possible) to another application but I really do