Removing Items While Using New For Loop

Consider this:
ArrayList<String> a = new ArrayList<String>();
... add some stuff ...
for(String s : a) {
// Do some stuff
if(some_condition) {
a.remove(s);
This will cause a ConcurentModificationException the a.remove(s) is ever run. Is there anyway to call the iterator.remove() method instead? The new syntax is much cleaner, and I'd like to use it, but I need to be able to call iterator.remove()
Anyone?

I think the code should iterate through a, putting
references to objects in an auxillary array and then
the loop will go through the auxilary array rather
than the original data structure. This perfectly
reasonable, but different implementation results in
drastically different results (the example above would
work fine). I see this as an issue of these general
language features being defined to close to the metal.
Their semantics are defined by their implementation
not by a sound language design decision that is
agnostic to different implementations.The enhanced for loop is defined in terms of java.lang.Iterable, a very simple interface, which can be implemented in many different ways. You can't get much farther from the metal. The concurrent modification exception is a feature of particular implementations of that interface. If you don't like those implementations, use others that behave differently. For example, you could use one of the CopyOnWrite collections implementations in java.util.concurrent, which never throw a concurrent modification exception. Your suggestion to copy the elements into an array is one (inefficient) implementation mechanism for such collections.

Similar Messages

  • I'm creating an array using a for loop, how do I get the values outside the loop while it is running? thanks

    I'm creating a set of values using a for loop and a shift register inside the loop. I want access to these values outside the loop as they are being created inside. When I connect a wire from the shift register to a display outside, it doesn't work. How do I do this? Thank you.
    Attachments:
    tamko_new.vi ‏29 KB

    I tried to create the local variable that was wired to numeric indicator inside the loop. If I try to connect this to the analog output outside the loop, the loop just starts blinking and nothing happens, am I doing something wrong? Thanks again.
    Attachments:
    tamko_new2.vi ‏29 KB

  • Create multiple VIs using a for loop

    Hi,
    I'm still pretty new to LabVIEW, so this question might be easy for you guys here..
    I'll simplify what I'm trying to do.
    I've got two numeric controllers that act as the rows and columns of a matrix.
    I'd like to take those numbers from these two controllers and use them to create a matrix of a certain picture.
    Example:
    The rows controller is given 3, and the columns controller is given 4.
    Using these numbers I would like the end result to show a certain image (let's say, a cube) multiplied on a 3 by 4 matrix.
    Let's say the picture is an X, then the end result should be:
    XXXX
    XXXX
    XXXX 
    I think I should be using a double for loop (one inside the other obviously), and I should also create the "position" property in order to display each picture of the cube in it's right place.
    The problem is that I don't know how to CREATE the pictures over and over again, while being able to control each one's position property.
    Any help would be GREATLY appreciated!
    Solved!
    Go to Solution.

    1) By "multiple VIs" I meant that I think that I need to create express VIs on the fly while running the for loop. I might be totally wrong here.
    2) Yes, by "numeric controllers" I meant numeric controls in the front panel.
    3) The matrix I'm referring too isn't an object nor a VI in LabVIEW but a virtual matrix that is the end result. I used the term "matrix" because the end result is actually a matrix (of rows and columns) of pictures..
    I'll try to elaborate and even simplify it more:
    Let's say I want to display one picture. That's easy, no problem there.
    Now let's say that I'd like to display n pictures on a one dimensional array. Just one row.
    What I think I need to do is to read from the numeric control in the front panel the number (n) of pictures, and then create them in a for loop, while using the "position" property to set the distance between each picture (using coordinates).
    My original question was just like the above, but for a two dimensional matrix/array. So I guess we can even simplify it even more, by saying it's only one dimensional.
    My way of action here might be totally wrong, and there might be an easier way or another way to go about this...
    Thanks for the quick answer!!  

  • Using a For Loop Index for Array Element Number?

    Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.
    Here's the situation:
    I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.
    What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.
    See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  
    I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.
    Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.
    Any help would be appreciated.
    Attachments:
    NeedForLoopForThis.PNG ‏30 KB

    Hello H.R. Dunham, and welcome to the forum!
    It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.
    As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:
    1) Gather data
    2) Split X and Y using standard array operations
    3) Create "template" cluster with shared X data
    4) Pass template cluster and Y-column array into an auto-indexed for loop.
    5) Insert processed Y data into cluster inside loop.
    6) Auto-index cluster data out of loop.
    This tutorial is probably also a good place to get started:
    Getting Started with NI LabVIEW Module 3: Loops
    http://www.ni.com/white-paper/7528/en/
    Hope that helps!
    Regards,
    Tom L.

  • Iterating through every other (or specified number) of element in an array using a for loop

    I am trying to go through an array but instead of autoindexing I want to skip every other element or maybe a number of elements that will be specified for the user.
    Basic functionality that I want to acheive is the following in C code.
    int temp_var = 10;
    int i=0;
    for(i=0; i<=1000; i=i+temp_var)
    I am very new to LabVIEW and I did not know how to use internal variables.
    Can this be acheived using shift registers?
    I am attaching the code I currently have for this. Let me know what you think.
    Thanks guys.
    Solved!
    Go to Solution.
    Attachments:
    24_Sep_NchanNSamp.vi ‏44 KB

    tbob wrote:
    I have been asking for a new For Loop style that would allow us to specify start, stop, and step conditions, but it seems that many people are just not for this idea.  Don't know why?
    See here.
    I wouldn't say there aren't many people for it.  The idea you linked to was one of a half dozen of basically duplicate ideas, including another one of your own.
    These two ideas have a fairly large number of kudoes showing people want the idea.
    Smart Iterators with Loops
    For Loop Increment

  • Weird problem with loading data from an XML using a for loop

    Hi,
    I have a strange problem. I have encountered this thing many a times but still don't know the proper workaround for it.
    I am trying to load swf file, a video file or an image. They can be present on a local system or on a remote server also. All the entries corresponding to the files to be loaded is made in an XML file. I traverse through the nodes of the XML using a for loop. On the complete event of loader info, example:.
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    I fill a container with the loaded data.
    My problem is when I am using for loop it doesn't works properly but if i use a statement like this:
    someFunc()
         if(i<arr.length())
         ... do something...
         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    private function onComplete(e:Event):void
    ... do something...
    i++;
    All files are loaded properly.
    I think this can be because the for loop processes pretty fast but the content takes time to load, which ultimately leads to some wierd results.
    Please let me know how can this thing be done correctly by using a for loop also.

    You don't want to use a for loop to load several items.  The way you almost appear to have it is the proper approach... load a file and use the completion of its loading to trigger loading the next file.

  • Using a For loop to call one array element at a time

    I have been working on a VI that reads a GPS unit, parses the data, outputs what I need, compares the actual GPS location to the desired location, determines a desired heading and moves on from there.  My question pertains to the number of desired locations I can input right now.  I need to be able to input a predtermined number of locations (not just the one that I can input right now).  I was told that it is possible to use a For Loop with an array and have the first set of Lat and Long values run through the VI and when everything is complete that the next set of values will be chosen.  Does this mean that I need to put the entire VI inside a For Loop and have the array update as soon as the VI has completed its first mission?  I understand the concept of how this work from other programming languages but I'm not sure how to implement the solution in LabVIEW.  Any help would be appreciated.
    Adam

    adamoutlaw wrote:
    Here is a portion of the VI.  I need two separate arrays, one for Latitude and one for Longitude, of the same size.
    I don't see any arrays in your code. Do you want to generate arrays form individual data points or do you want to process arrays, one element at a time? Both can take advantage of autoindexing. Here's a simple picture.
    Your VI contains a weird mix of DBL and EXT precision. Most likely all you need is DBL. Keep your representations consistent!
    Message Edited by altenbach on 08-02-2007 07:14 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Indexing.png ‏4 KB

  • How to improve the load performance while using Datasources for the Invoice

    HI All,
    How to improve the  load performance while using Datasources for the Invoice . Actually my invoice load (Appx. 0.4 M records) is taking very long time nearly ~16 to 18 hrs  to update data from R/3 to 0ASA_DS01.
    If I load through flat file it will load with in ~20 Min for the same amount of data.
    Please suggest how to improve load performance.
    PS: I have done the Inpo package settings as per the OSS note.
    Regads
    Srininivasarao.Namburi.

    Hi Srinivas,
    Please refer to my blog posting [/people/divyesh.jain/blog/2010/07/20/package-size-in-spend-performance-management-extraction|/people/divyesh.jain/blog/2010/07/20/package-size-in-spend-performance-management-extraction] which gives the details about the package size setting for extractors. I am sure that will be helpful in your case.
    Thanks,
    Divyesh
    Edited by: Divyesh Jain on Jul 20, 2010 8:47 PM

  • Transposing data in an array using a For Loop

    I am trying to transpose some data in an array using a  for loop starting from the size of the array then decrement down to 0. Can someone please help if you have an example?
    Solved!
    Go to Solution.

    I feel as if reverse 1D array may help
    Edit: misunderstood what your second post meant.
    CLA, LabVIEW Versions 2010-2013

  • Blank spaces while using GUI_DOWNLOAD for Chinese characters

    Hi,
    While using GUI_DOWNLOAD for chinese characters I have used a code page option of 8300 for Chinese.
    The file which is getting downloaded in a notepad has some Chinese characters coming under some headings.
    After that columns other columns are getting shifted towards the right.
    This is working correctly for English characters.
    Can someone please help me.
    Now I am using CL_GUI_FRONT_END_SERVICES=>GUI_DOWNLOAD.
    What special options should I pass now.
    Regards,
    Subhashini

    Hi,
    I only solved my problem by using different code pages 8400 and 8300 for Chinese and Taiwanese characters.
    I fixed the lengths of the fields by converting them to hexadecimal string and back to string using these function modules as below.
    DATA:lv_xstring TYPE xstring,
           lv_temp TYPE string.
      DATA: lv_conv TYPE REF TO cl_abap_conv_in_ce.
      lv_temp = p_name.
      CALL FUNCTION 'HR_KR_STRING_TO_XSTRING'
        EXPORTING
          codepage_to      = p_codepage
          unicode_string   = lv_temp
          out_len          = p_outlen
        IMPORTING
          xstring_stream   = lv_xstring
        EXCEPTIONS
          invalid_codepage = 1
          invalid_string   = 2
          OTHERS           = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
       EXPORTING
         from_codepage = p_codepage
         in_xstring    = lv_xstring
         out_len       = p_outlen
       IMPORTING
         out_string    = p_string.
    Create a Conversion Instance
    lv_conv = cl_abap_conv_in_ce=>create(
    encoding = p_codepage
    input = lv_xstring ).
    v_conv->read( IMPORTING data = p_string ).
    Regards,
    Subhashini

  • How to Remove items without opening new dispute for FHA Mortgage approval

    Hello, these forums are very helpful. How do I remove items from the bureaus without filing a dispute? For example, I have several old accounts that are expired now. On 2 of them, I tried calling the creditors directly and they were so old that they said they had no information. I can't file a "dispute" with the bureaus because as you know, you can't close on a mortgage with an open dispute and I don't have time to wait 30 days. I can't quite go to the creditor when they're like "it's so old we have no information." The other issue I have is there are some blatant errors. For example, student loans errors. I have letters from my student loan company saying they've corrected with the credit bureaus -- but then they show up. What should I do? Again, I can't open disputes because I can't have an open dispute and close on a loan. LVNV put something on my credit report for a dental bill I paid in cash. It was years ago. I don't know how to go about proving I paid it. Last but not least I have a charge-off from Bank of America that's reaching the 7 year mark in 2 months. Is B o A good about removing after it hits that mark? Should I even try a goodwill ask of them to remove it early or at least update it to a 0 balance? (They didn't sell it so it still shows a balance) Or anything? I'd be afraid of offering any type of payment for fear they'd open the loan and re-age it since it's going to fall off in a month. All help appreciated

    It wont be BofA that removes it at 7 years, it will be the credit rteporting agencies. You can ask for an early exclusion (I had good success with TU and EX and didn't have anything on EQ to try on.) Call and ask for EARLY EXCLUSION. TU may take a few tries before you get someone that knows what you are talking about. EX was a piece of cake. You will need a report number to get thru on EX phone system (the last copy of your free report from annual credit report will have a 10 digit number at the top). If the others are old you can try the same thing, otherwise you may have to contact the creditor and get them to email you letters stating it should be updated and get those in the hands of the

  • Can I use a for loop to add anonymous ActionListener objects?

    I have a setListener() method that has the following inside:
    for(int k = 0; k < buttons.length; k++)
        buttons[k].addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                g2.setColor(colors[k]);
    }I have a JButton array and a Color array and I was hoping I could add them quickly in one shot rather than manually adding an anonymous ActionListener 9 times (I have 9 components). It tells me I need to make k final for an inner class and when I tested it by removing the for loop and keeping k as a final integer, it works. Is there a medium such that I can achieve what I want more or less while respecting Java's syntax?
    Any input would be greatly appreciated!
    Thanks in advance!

    s3a wrote:
    The local variable exists on the stack for as long as the method is executing. Once the method ends, that variable no longer exists. The newly created object, however, can continue to exist long after the method has ended. So when it's referring to variable X, it cannot refer to the same X as the one in the method, because that variable may no longer exist.Sorry for picking on little details but I am still not fully satisfied.
    Earlier I questioned if the local variable changed, but now let's say that that variable no longer exists at all, why does that even matter if the inner class copied the value and is keeping it for itself? What do you mean? The variable that existed in the method ceased to exist when the method ended. The inner class, however, can continue to live on, and can continue to refer to what we see as the same variable. However, it obviously can't be the same variable, since, in the world of the inner class, it still exists, while in the world of the method, it does not.
    This is completely independent of whether the variable changes or not. Regardless or whether the variable changes we still need two copies--one that goes away when the method's stack frame is popped, and one that lives on as long as the inner object does.
    Then, because there are two copies, the designers decided that the variable has to be final, so that they wouldn't have to mess with the complexity of keeping two variables in sync.
    That explanation leads me to believe that there is no copy and that there is some kind of "permanent umbilical cord" between the inner class and the local variable.Wrong. There has to be a copy. How else could the inner class keep referring to it after the method ends?
    Also, does marking it as final force it to be a permanent constant "variable" even if it's not a field "variable"? Or, similarly, does making a "variable" final make Java pretend that it is a field "variable"?Making a variable final does exactly one thing: It means the value can't change after it's been initialized. This is true of both fields and locals.
    As for the "pointless" byte-counting, I really don't see how it's confusing unless you're an absolute beginner. If I see somebody using a byte, I assume they have a real reason to do so, not pointless byte-hoarding. Then when I see that it's just a loop counter, I wonder WTF they were thinking, and have to spend some time determining if there's a valid reason, or if they're just writing bad code. Using a byte for a loop counter is bad code.
    I could then ask, why are people not using long instead of int and saying that that's using int is too meticulous?Part of it is probably historical. Part of it is because at 4 bytes, and int is exactly on word on the vast majority of hardware that Java has targeted since it came out. 8-byte words are becoming more common (64-bit hardware) but still in the minority.

  • Can a waveform graph be used without for loop

    i would like to know if a waveform graph can be used without a for loop and if so, how? I tried using a while loop only, but the reading becomes too fast.
    can someone advise

    Dear nebb,
    first of all, graph is usually an offline plot of the acquired data but to use it as an online display u need to use build arrays in for/while loop which keeps on adding new points & plots in waveform graph.
    I am including a vi which incorporates a while loop in which by using build array, points keep on increasing & simultaneously they are plotted in the waveform graph.
    Using for or while loop, it has no concern with speed. it depends on the code inside the loop which makes them faster or slower.
    For making slow readings, you can put some delay inside while looping.
    Hope this works. YOur feedbacks are welcome.
    Best Regards,
    Nirmal Sharma
    India
    Attachments:
    waveform_graph_without_for_loop.vi ‏17 KB

  • Using a for loop to populate JButton values with letters of Alphabet

    I am trying to create a column of 26 JButtons, with the text of the button being a letter of the alphabet, but I want to find a faster way to do it. I've tried using the Character class, but it won't let me use an int variable with the constructor. The primitive char class won't allow the '++' operand. I was thinking of using the Unicode values, but I haven't figured out a way to use them in a for loop. Any ideas?

    Hope this helps :-)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class CreateButtons {
         private static JPanel ToolPanel;
         final static JFrame ToolFrame = new JFrame("Drawing Tools");
         public static void main(String[] args) {
              ToolPanel = new JPanel(new GridLayout(17, 1));
              ToolPanel.setBorder(BorderFactory.createTitledBorder("Tools"));
              for(int i= 0; i < 26; i++) {
                   char c = (char)('a' + i);
                   makeButton(c);
              ToolFrame.getContentPane().setLayout(new BorderLayout());
              ToolFrame.getContentPane().add(ToolPanel, BorderLayout.CENTER);
              ToolFrame.setLocation(100, 100);
              ToolFrame.pack();
              ToolFrame.show();
         static public void makeButton(char buttonName){
              JButton button = new JButton( Character.toString(buttonName) );
                   button.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e){
                             System.out.println(e.getActionCommand());
         ToolPanel.add( button );
    }

  • Net Price showing zero while using BAPI_PO_CREATE1 for me21n

    Dear All,
    I am using BAPI_PO_CREATE1 for ME21N. The problem is, after execution of the program the error msg it shows-
    No instance of object type PurchaseOrder has been created. External reference:
    Purchase order still contains faulty items
    Net price must be greater than 0
    The values are coming from excel file.
    Please tell me where I am doing wrong.
    With regards,
    Rosaline.

    Hi,
    Symptom
    You create a purchase order with BAPI_PO_CREATE1 or you add an item to an existing purchase order with BAPI_PO_CHANGE. You assign a value in field POITEM-NET_PRICE. However, this value is not transferred. If it was not possible for you to determine any conditions, the system generated the error message 06218 'Net price must be greater than 0'.
    Other terms
    BAPI_PO_CREATE1, BAPI_PO_CHANGE, price, net price, gross price, conditions, price determination, condition type, 06218, EKPO-NETPR, NETPR, POITEM-NET_PRICE, NET_PRICE, PO_PRICE, BAPI_PO_PRICE, BUS2012, PurchaseOrder.CreateFromData1, CreateFromData1, PurchaeOrder.Change
    Reason and Prerequisites
    This function has not been available up to now. You could also assign conditions via the condition tables.
    Read also Notes 399791, 428621, 529287, 578253 and 539950 for this.
    Solution
    The present note adds field PO_PRICE to table POITEM. PO_PRICE can have the values ' ', '1' or '2' with the following meaning:
        PO_PRICE = ' ': The price determination is carried out as before.
        PO_PRICE = '1': The value assigned in field NET_PRICE is transferred as a gross price, that is it is set in the condition type that is defined as a base price in the calculation schema. All other condition types remain unchanged. No conditions are copied from the last document.
        PO_PRICE = '2': The value assigned in field NET_PRICE is transferred as a net price, that is it is set in the condition type that is defined as base price in the calculation scheme. All other condition types are deleted.
    Note the following
    The following restrictions apply to field PO_PRICE:
        If you assign conditions via the BAPI interface, these are always transferred. This is carried out independently of the value that you assign in field PO_PRICE.
        If you add a new item to a purchase order with BAPI_PO_CHANGE, it does not suffice to fill field POITEM-NET_PRICE on item level. The corresponding currency must be specified explicitly on header level.
        You can only use field PO_PRICE during the creation of a purchase order item. If you want to change the price of an already existing item, you can only do this via the conditions.
        If you fill field POITEM-PO_PRICE, you must enter an 'X' in POITEMX-PO_PRICE so that the value is transferred.
    Correction
    The correction is made available via R/3 support package. If you want to implement the note manually, proceed as follows:
        1. Make sure that your system contains Notes 494759, 552189 and 578253.
        2. Create data type BAPI_PO_PRICE with the following attributes:
                        Short text:
                           Price transfer indicator: 1  = gross, 2 = net
                        Package: ME
                        Domain: BPUEB
        3. Extend structure BAPIMEPOITEM (directly after NO_ROUNDING):
                        Component: PO_PRICE
                        Component type: BAPI_PO_PRICE
        4. Extend structure BAPIMEPOITEMX (directly after NO_ROUNDING):
                        Component: PO_PRICE
                        Component type: BAPIUPDATE
        5. Extend structure MEPOITEM_DATA (directly after NO_ROUNDING):
                        Component: PO_PRICE
                        Component type: BAPI_PO_PRICE
        6. Extend structure MEPOITEM_DATAX (directly after NO_ROUNDING):
                        Component: PO_PRICE
                        Component type: BAPIUPDATE
        7. Implement the correction instructions in your system.
    regards,
    Ravi
    Edited by: Parupelly on Dec 14, 2011 1:30 PM

Maybe you are looking for

  • Nano not showing up in iTunes or My Computer

    I had to reformat my computer hard drive and reload my computer with Windows Vista Ultimate. I lost all of my music on my computer but they still are on my Nano. I tried to reload the music from my Nano to my computer but that didn't work and now I c

  • CC Help and tutorial file links don't work

    The help file and tutorial links on on my CC desktop and on all my apps do not work. Clicking on the help links defaults to a windows "notepad" that shows the code for the link.  GeorgeReinstalling CC desktop or the app does not solve the problem. Wh

  • SDO_LRS.OFFSET_GEOM_SEGMENT

    Hello folks, Oracle EE 11gR2 w/spatial So I have this geometry that I am working on.  I am using it as a base intersection and I want to be able to offset it in pretty much any direction.  The image ( A screenshot from geoRaptor ) is below: As you ca

  • User exit to run before importing abap transport in TMS

    Hi, I need to run a check before importing an ABAP transport. I've seen a BADI that can be used after transport, also handy, but I really need to check dependencies before importing as well. Is there a user exit or badi that can do this? Thanks Tom

  • When i open new tab my all bookmarks and add on's remove automatically, what can do for locking this???

    when i open new tab my all bookmarks and add on's remove automatically, what can do for locking this???