How to delete an  element in an array...(simple way)

hi,
Newbie here... please help how to delete an element in an array list?
there are alot of codes but they're complicated for a newbie like me..
(simple codes would be better ..:) thank you...

makk_88 wrote:
since u want the simple method.....
just overrite the position of the element that need to be deleted with the next element in the array..
by doing this, element need to be deleted will not be accessibe..
i think u got..what i'm saying.
thnx..Mak,
Say we wish to delete the second element of an array a[1]. Do you really believe that a[1] = a[2] somehow magically deletes a[1]? I really don't think so Tim.
Two eggs, minus 1, equals two eggs? Interesting theory, but I think you're probably wrong.
*@OP:* My advise is just use an ArrayList.
Cheers. Keith.

Similar Messages

  • How to show the elements of an array?

    How to show the elements of an array, when the array size changes every loop?
    It's possible to use node property?
    thanks
    Vicens
    Win XP/ LV7.1
    Attachments:
    show elements.PNG ‏184 KB

    Basically it is (at least in LV8.0). There is a property "Number of Rows" which sets the number of visible rows. If your 1D array is placed horizontally, use "Number of Columns".
    Using LV8.0
    Don't be afraid to rate a good answer...

  • HOW TO DELETE DUPLICATE ELEMENT IN A VECTOR

    Hi everybody!
    If I've a vector like this vectA={apple,orange,grape,apple,apple,banana}
    and I want final result be vectB={apple,orange,grape,banana}.
    How should I compare each element in vectA and delete duplicate element. Like here duplicated element is apple. Only one apple remain in the vectB.
    Any help,
    Thanks.

    Hello all. Good question and good answers, but I would like to elaborate.
    To begin with, you specifically asked to map the following:
    {apple,orange,grape,apple,apple,banana} ==> {apple,orange,grape,banana}
    Both of cotton.m's solutions do NOT do this, unfortunately. They are both useful in particular cases though, so think about what you're trying to do:
    cotton.m's first solution is best if order does not matter. In fact, as flounder first stated, whenever order doesn't matter, your most efficient bet is to use a Set instead of a List (or Vector) anyways.
    Set vectB = new HashSet(vectA);This code maps to {banana, orange, grape, apple}, because HashSets are "randomly" ordered.
    cotton.m's second solution is good if you want to impose NEW ordering on the List.
    Set vectB = new TreeSet(vectA);This code maps to {apple, banana, grape, orange}, because TreeSet uses alphabetical-order on Strings by default.
    java_2006, your solution is the most correct, but it's a little verbose for my taste :)
    more importantly, the runtime-efficiency is pretty bad (n-squared). calling Vector.contains performs (at worst) n comparisons; you're going to call it n times! Set.contains usually performs 2 comparisons (constant, much better), so I suggest you USE a Set to do the filtering, while still sticking with your good idea to use a List. When the ordering is "arbitrary" (so can't use TreeSet) but still relevant (so can't use HashSet), you're basically talking about a List.
    I think saving A LOT of time is worth using A LITTLE extra space, so here, let's save ourself some runtime, and some carpal-tunnel.
    import java.util.*;
    class Foo {
         public static void main(String[] args) {
              String[] fruits = {"apple","orange","grape","apple","apple","banana"};
              List     l = Arrays.asList(fruits),
                   m = filterDups(l);
              System.out.println(m);
         // remember, both of the following methods use O(n) space, but only O(n) time
         static List filterDups(List l) {
              List retVal = new ArrayList();
              Set s = new HashSet();
              for (Object o : l)
                   if (s.add(o))
                        retVal.add(o);     // Set.add returns true iff the item was NOT already present
              return retVal;
         static void killDups(List l) {
              Set s = new HashSet();
              for (Iterator i = l.iterator(); i.hasNext(); )
                   if (! s.add(i.next()))     
                        i.remove();
         // honestly, please don't use Vectors ever again... thanks!
         // if you're going to be a jerk about it, and claim you NEED a Vector result
         // then here's your code, whiner
         public static void mainx(String[] args) {
              String[] fruits = {"apple","orange","grape","apple","apple","banana"};
              List l = Arrays.asList(fruits);
              Vector v = new Vector(l);
              killDups(v);
              System.out.println(v);
    }

  • XMLBeans - how to delete an element?

    Guys,
    How do you delete an element within an xml data element?
    If there's more than one way what are they?
    Currently, I've generated XML java objects. I see a setNil() method and a couple removeXXX methods but neither appear to delete the element I'm trying to give the axe to.
    Thanks!
    -mark

    makk_88 wrote:
    since u want the simple method.....
    just overrite the position of the element that need to be deleted with the next element in the array..
    by doing this, element need to be deleted will not be accessibe..
    i think u got..what i'm saying.
    thnx..Mak,
    Say we wish to delete the second element of an array a[1]. Do you really believe that a[1] = a[2] somehow magically deletes a[1]? I really don't think so Tim.
    Two eggs, minus 1, equals two eggs? Interesting theory, but I think you're probably wrong.
    *@OP:* My advise is just use an ArrayList.
    Cheers. Keith.

  • How to insert 1 element in 2D array?

    There is an example of how to replace element in 2D array, but I would like to insert (not replace), I use the insert element. it does not work for 2 D array.
    Attachments:
    find_and_map_defect_to_image736X554.vi ‏46 KB

    You need to tell more about what you want done. What exactly does it mean
    to insert into a 2D array? Are you inserting into the row or column or
    both? By that I mean to ask what parts of the array get their indices
    incremented. Then what should happen at the endpoints? If you insert a
    point into one row then that row will have one more element than the others.
    Should the last element in that row be lost or should the other rows get a
    zero appended?
    "trout00" wrote in message
    news:[email protected]..
    > There is an example of how to replace element in 2D array, but I would
    > like to insert (not replace), I use the insert element. it does not
    > work for 2 D array.

  • How to delete an element in arraylist??

    here i have an array list which contain details of an address book
    I want to delete one element in the list
    but its not deleting
    Could anyone please take a look and help me
    tank u in advance!!
    else if (X.compareTo(F)==0)
       {System.out.println("Pour supprimer une fiche : saisir le NUM INDEX.");
        Integer c1 = new Integer(0);
        Z = clavier.readLine();
        c1=Integer.valueOf(Z);
        System.out.println("Vous allez supprimer la fiche "+c1);
        for( Iterator it= l.iterator(); it.hasNext();) {
          Object p =it.next();
          relations R=(relations)p;
            if (R.getnumero()==c1)
           l.remove(l.indexOf(p));}
          for( Iterator it1= l.iterator(); it1.hasNext();) {
             Object o =it1.next();
             if (o.getClass().getName()=="carnetadresses.contact")
               ((relations) (o)).affiche();
               }break;
      }

    It's a good thing you use code tags for posting here. Could you now consider using code conventions?
    - Why is the second loop nested in the first one? (this second loop looks weird anyway...)
    - The Iterator has a remove method. You should use it in such case.
    - Looks like you have a malpositioned/misused break statement (which is probably the reason why nothing happen, as it terminates the for loop after the first iteration.)

  • How to average each element in an array

    I have data from a Gage Card that I would like to average.  I am tuning a laser over a 50 mA range and for each 1mA increment in current, I am taking 100 scans.  Each scan consisting of about 200 points.  I cannot average more than 10 shots using the Gagecard so I would like to capture 100 scans, and average them to reduce noise.  Currently, I have my capture vi inside of a for loop which repeats 100 times and each scan writes to a file, but I would like ony 1 scan (the lower noise averaged one) per current increment.  
    How can I average each element of 100 arrays and output this to an array?
    Thanks for the help 

    It sounds like you want to average element 0 across 100 arrays and make that element 0 of the new averaged array.  Then average element 1 across 100 arrays and make that element 1 of the new array ...   ?????
    How are you working with your 100 1-D arrays now? 
    What you should do is make a 2-D array where one dimension is 100 (for the number of individual arrays) and the other dimension is how many elements are in those 100 1-D arrays.  Then you can use for loops with auto indexing to break the 2-D array down into each row or column, do the average of that array, and autoindex on the other side to build back up into the new 1-D array of averages.  You may need to to a transpose array going into your for loop in case the arrays are indexed in the wrong direction.
    Message Edited by Ravens Fan on 01-21-2008 04:26 PM
    Attachments:
    Example_BD.png ‏6 KB

  • How to find the elements of an array

    I want to find the number of elements in an array, and I can't find the tutorial that shows how to find it. If anyone could point me in the right direction, it would be greatly appreciated.

    warnerja wrote:
    flounder wrote:
    DrLaszloJamf wrote:
    You mean x.length?<pbs>
    Depends upon your interpretation of "number of elements in the array"
    int[] numbers = new int[10];
    numbers[0] = 42;
    numbers[1] = 666;Number of elements in the array is 2 not 10.
    </pbs>If you used something other than a primitive type for the array element type you could have a case. A value of integer zero for the other elements is still a value, so there are indeed 10 elements there.Even if it were not primitive, every element would have a value. That value would either be null or a reference.

  • How to delete cost element name from group after deleting the cost element

    Hi,
    Please let me know how to delete the cost element number  from the Cost element group hierarchy.I have deleted cost element but still showing only the CE number---no valid master record.If I d not want this to be visible within hierarchy let me know what should I do.
    Thanks

    Hi
    Go to change cost element group select the cost element click on select tab (3rd Tab from Left) it will take u to new screen in that screen select remove tab (1st tab from left)
    Regards
    Sandesh

  • How to add new elements in an array of Objects of Type Figure??

    I have a Figure class which has many attributes(variables). Then I create an array of Figures for example
    Figs[] figures = new Figure[18];
    Later I need to add new Figures to this array at different positions. In my case I have to use the same array.
    Is there any way so I can add new Figure elements to this array??
    If u have an answer to this question, please share with me.
    Thanks
    Amit

    There are many ways to solve this problem, including creating new arrays as needed, and using System.arraycopy() to move things around. However, the best way is to use ArrayList, as discussed above.
    What you cannot do is use toArray() and cast back to String[]. Object[] is not a subclass of String[], even if all of the objects in the Object[] are Strings!
    There are two ways to get around this. Create a String[] and copy the Object[] into it with System.arraycopy, or the easy way, which is to use the toArray(Object[]) method. It allows you to specify by example the array class you wish returned. If the array is large enough, it will populate the array directly, otherwise it will create a new one of the same base class. That means any of the following approaches will work, the final decision is mostly a matter of style:
        // create a zero length array to pass as an exemplar
        public final static String STRING_ARRAY_TYPE[]  new String[0];
        String s[] = (String[]) a.toArray(STRING_ARRAY_TYPE);Or:
        String t[] = new String[a.size()];
        a.toArray(t);Or:
        String t[] = a.toArray(new String[a.size()]);;I prefer the first approach generally, and it avoids any race conditions between the evaluation of the ArrayList size and the toArray; however, since ArrayList methods are not synchronized, you probably should do some synchronizing of your own.
    Hope this helps.

  • How to replace cluster element in an array?

    hi,
    I have understood preferable choice is to initialise array first and replace elements in an array instead of inserting new element in an array e.g. in a while loop.
    So I started to this evaluate since I have an application where I want to read lots of measurements from a txt file and display them in a XY graph. XY graph must show Y value and corresponding X value either red if it is out of range and in green if it is in range. I found a solution to do it with an array of clusters.
    In attached example I have two different methdologies represented. My problem is that upper solution doesn't display content of all measurements. Can somebody tell me what I'm doing wrong ?
    regards,
    petri
    Solved!
    Go to Solution.
    Attachments:
    plot test 3.vi ‏19 KB

    Petri wrote:
    ... using cluster with three elements was a method I found to put red and green dots in one XY graph, eg. Y=coordinateY, X(green)=NaN,X(red)=coordinateX. Perhaps there is a better way to display the data, but I couldn't find it.
    That is an odd thing and makes little sense. Why three? four, five, etc are NOT supported, so what if you want more than one color? (in range, fail high, fail low?). For more detail see the discussion here.
    In any case, reading all these values from a datafile and creating xy plots is trivial. I would recommend to use complex data. a single complex array will graph IM vs RE. For multiple plots, combine them using "build cluster array". No loops needed.
    Here's a quick draft. Of course you need to decide if the data is in columns or rows, etc. so modify as needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    plot2XY.PNG ‏7 KB

  • I would like to now how to delete a photo.  Plain and simple.

    Why is it that delete does not mean delete?

    The links below have instructions for deleting photos.
    iOS and iPod: Syncing photos using iTunes
    http://support.apple.com/kb/HT4236
    iPad Tip: How to Delete Photos from Your iPad in the Photos App
    http://ipadacademy.com/2011/08/ipad-tip-how-to-delete-photos-from-your-ipad-in-t he-photos-app
    Another Way to Quickly Delete Photos from Your iPad (Mac Only)
    http://ipadacademy.com/2011/09/another-way-to-quickly-delete-photos-from-your-ip ad-mac-only
    How to Delete Photos from iPad
    http://www.wondershare.com/apple-idevice/how-to-delete-photos-from-ipad.html
    How to: Batch Delete Photos on the iPad
    http://www.lifeisaprayer.com/blog/2010/how-batch-delete-photos-ipad
    (With iOS 5.1, use 2 fingers)
    How to Delete Photos from iCloud’s Photo Stream
    http://www.cultofmac.com/124235/how-to-delete-photos-from-iclouds-photo-stream/
     Cheers, Tom

  • How to delete empty element in popup list

    I have a question about a suspicious behaviour in Forms Builder 10.1.2.0.2.
    When I have a list object (pop up list) I can define some values in the attribute palette of the object.
    So you can set a shown name and a value behind. In this little window to set the items of the popup list you get automatically a white empty item at the end of the list. When I click now on this empty item (you do so, when you want to add an item) Forms Builder automatically adds an new empty item at the end.
    When I click this new empty item, Forms Builder adss another empty one ... and so on.
    It´s very suspicious because, when I end this dialog with "OK", it will be saved and when I open the form (over web) I have at the end of the list one, two (or more) empty elements in list.
    But I can´t delete this empty ones from the list in Forms Builder.
    So my question:
    how can I delete empty items in a popup list??
    I try it with hit "del" button at keyboard or delete the set value for the item (I hope Forms Builder delete items without value). But all does not help.

    Thanks jwh for this great solution! :)
    On my german keyboard it is:
    ctrl+< for deleting a line
    ctrl+> (= ctrl+shift+<) for adding a new line
    Thanks! :)
    I have another question (you can maybe help me, too?).
    On this popup lists you can have several items. When you open a form (via web) and the list has more than x items (maybe 5 or 6) the form shows a scroll bar on the right side.
    Is there any poosibility to set how much items has to show and only show a scroll bar when there are more items in the list?
    Or other way: set the maximum of shown items so big, that there will be no scroll bar.
    Message was edited by:
    ulfk

  • How to pick random element in 2D array

    This is the contents of my constructor. How is the best way to pick a random element in a 8x8 array and assign it "Q"?
         public DancingQueen()
              board = new char [BOARD_SIZE][BOARD_SIZE];
              for (int i = 0; i < board.length; i++)
                   for (int j = 0; j < board.length; j++)
                        board[i][j] = SPACE;
                   Random generator = new Random();
                   int r = generator.nextInt(8);
                   int c = generator.nextInt(8);     
                   board[r][c] = "Q";

    Better make that 'Q' instead of "Q". The rest is fine though.
    kind regards,
    Jos

  • How to delete an element in a tree?

    how can i delete element in my tree?
    after that to refresh the tree?

    OK. You should have the rootNode and then your three other nodes added to the root (fiche, famille, etc)?
    I'm currently creating an application that uses a tree with two branches. The code I posted works regardless of the branch the node I wish to remove belongs to.
    It does depend as well how you are storing your nodes. I mean I'm just storing the node referenced by a string in a hashtable for easy reference. I gather that you want to click the node for it to disappear?

Maybe you are looking for

  • A few more questions about batteries

    Hi folks, new here. 1. According to www.apple.com/batteries, we don't have to worry about this Nickel-based batteries stuff when charging (cause iPods are Lithium-based). If so, do I really need to charge for 4 hours the first time? Why? 2. I've had

  • Query construction issues...

    So what i'm trying to do is output a single row for each person_id. Additionally, if a person_id has a type_id of 1 then i would like a column to output 'YES' otherwise 'NO' and the same goes for type_id of 0. Oracle version: 10.2G Content of TableX

  • Need to change the buffering of a tbale

    Hi , Im trying with transaction SE13 to change the buffering of a table (usr02) , but when i change the buffering the system tell me that the value is not permited , this happen with all the tables that have the data class 'APPL0 , APPL1 y APPL2' , I

  • Cannot print on EPSON Stylus Photo R230 after my Yosemite update OXSUpdcombo 10.10.3.dmg

    After I Updating our iMac 21.5"  i5, Mac Pro 13" i5 and 15" i7 ( Retina ) with OXSUpdcombo10.10.3, we cannot print on my Epson,  connection via USB, Printer Driver still there, I try to un install and reinstall with driver EPSONPrinterDriver3.0.dmg ,

  • Is there any place i can get installation cd or file for wvc54g?

    Hi, i have purchased a wireless linksys cam (wvc54g) is there any place i can get the installation cd or file from linksys site? thanks.