URGENT: Removing element from a vector?

ok I have a text database where the lines look something like this:
5876,Tigger,50.00
7892,Piglet,25.00
my problem is I have to remove an element that I don't know the index of, so I figured I have to search the vector for the number(eg, 5876) and return the index so I can remove it, but I don't know how to do this. Please help me

Try this:
public class Parser
public Vector read(InputStream in) throws IOException
   Vector structures = new Vector();
   StringBuffer buffer = new StringBuffer(128);
   int n = -1;
   while((n = in.read()) != -1)
      char c = (char)n;
      if(c == '\n')
         structures.add(getDataStructure(buffer.toString()));
         buffer.delete(0, buffer.length());
      } else
         buffer.append(c);
   if(buffer.length() > 0)
      structures.add(getDataStructure(buffer.toString()));
   return structures;
protected DataStructure getDataStructure(String string)
   DataStructure structure = new DataStructure();
   StringTokenizer st = new StringTokenizer(string, String.valueOf(','));
   structure.id = (String)st.nextElement();
   structure.name = (String)st.nextElement();
   structure.price = Float.parseFloat((String)st.nextElement());
   return structure;
public class DataStructure
   String id;
   String name;
   float price;
   public DataStructure() {}
   public boolean equals(Object o)
      if(o instanceof DataStructure)
         return id.equals(((DataStructure)o).id);
      } else if(o instanceof String)
         return id.equals((String)id);
      return false;
}Now you can keep track of the info in a better way.
If you have
5876,Tigger,50.00
5876,Tigger,50.00
5876,Tigger,50.00
5876,Tigger,50.00
5876,Tigger,50.00
Stored in a file, you can do this:
Vector v = new Parser().read(new FileInputStream("..."));
Structure s = (Structure)v.elementAt(0);
System.out.println(s.name);
v.remove("5876");Isn't that nice?
Note that the code may or may not compile.
Hope it helps,
Nille

Similar Messages

  • Removing element from vector

    I am trying to remove an element from a Vector and using the ff code:
    Vector abc = getVector();
    int index = 0;
    abc.removeElementAt(index);
    The element is not being removed, when i go back to check the number
    of elements in the vector, it is still the same.
    Please give me any ideas to make this work.

    Try this,
    Vector abc = getVector();
    int index = 0;
    System.out.println("Size before : "+abc.size());
    abc.remove(index);
    System.out.println("Size after : "+abc.size());
    What is the o/p?
    Sudha

  • Kill a thread and remove the element from the vector

    Hi All
    I have attached each Vector element to a thread which I later want to kill and remove that element from the Vector.
    Thread.join(milliseconds) allows this functionality to let the thread die after n milliseconds.
    However, I want to delete this element from the Vector now.
    Can someone please throw some light on this?
    Here the code I have written for this:
    try
         System.out.println(counter);
         int xCoord = generator.irand(25,200);     // X-coord of AP
         int yCoord = generator.irand(25,200);     // Y coord of AP
         listMN.addElement(new MobileNode((int)mnId,new Point2D.Double(xCoord,yCoord)));
         listMNcoords.addElement(new Point2D.Double(xCoord,yCoord));
         for(int i=0;i<vnuBS.returnBSList().size();i++)
              if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=3)&&(vnuBS.returnBSList().get(i).getChannelCounter()>0))
                   double c = exponential() * 10000;
                   long timeToService = (long)c;
                   System.out.println("BS "+vnuBS.returnBSList().get(i).id+" is connected to MN ");
                   vnuBS.returnBSList().get(i).reduceChannelCounter();
                   System.out.println("Channel Counter Value Now: "+vnuBS.returnBSList().get(i).getChannelCounter());
                   mobileNodesThread.addElement(new Thread(listMN.elementAt(mobileNodeCounter)));
                   mobileNodesThread.elementAt(mobileNodeCounter).setName(mobileNodeCounter+"");
                   mobileNodesThread.elementAt(mobileNodeCounter).start();
                   mobileNodesThread.elementAt(mobileNodeCounter).join(100);
    //                              System.out.println("Died");// thread dies after join(t) milliseconds.
                   System.out.println("ListMN getting generated : " + mobileNodesThread.get(mobileNodeCounter));
              else if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=0))
                   listMN.remove(this.listMN.lastElement());                         //dropcall
                   System.out.println("Removed "+mnId);
                   removeCounter++;
                   mnId = mnId--;
                   mobileNodeCounter--;
              mnId = mnId+1;
         Thanks a lot.

    I'm not sure if what you are trying to accomplish is correctly implemented.
    The method join does not kill the thread. It will wait for the specified time for the thread to exit. If you want the thread to run for a specified ammount of time, develop the run method of that thread with that in mind. Do not try to kill it from the outside, but let it terminate itself (gracefull termination).
    Now for your question regarding the vector (you should probably be using ArrayList nowadays): I would implement the observer pattern for this job. Make the threads post an event on the interface when they are done, let the main thread register itself with the threads and synchronize the method that handles the events. In that method you can remove the object from your list.
    I'm not sure if you want to use thread anyhow, could you tell us what it is that you are trying to accomplish?

  • How to remove value from a vector (from its top index 0)

    HI Friends
    A basic question. In my code i am adding values in vector (v). Now i want to remove the values from the top of the vector (from index 0) and move them in an variable temp. How can i do it. I know there is a method remove in vector. but i am not sure how to use it.Can anybody show me how to do this?
    here is my peice of code
       public void result (){
            int temp1,temp2;
            for(int i=0; i<=  3000;i++){
               v.removeElement(i);
           }Thanks alot in advance

    Well, i'm Not sure what ur problem is...?!?
    Do U mean to say,
    You need to just remove the 0'th element from a Vector & store THAT in a element called temp..?!?
    Plz. have a look at the Vector class API in (for Java 1.4)
    http://java.sun.com/j2se/1.4.2/docs/api/
    There's a remove( ) which takes the index of the element to be removed...
    In ur case, u could say, for example
    Object temp = myVector.remove(0);or more appropriately,
    SomeType temp;
    temp = (SomeType)myVector.remove(0);--fritz                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Remove element from xml using dom.

    i want to remove an element from an xml file using dom.
    i remove the element but the whole content of the file is also deleted.
    how can i rewrite the file.

    vij_ay wrote:
    subject :Remove element from xml,but if empty element in input file then output should be <tag></tag>, not like <tag.xml/>I assume you mean <tag/> but why do you want this? Any application that will not accept this valid XML construct is flawed and a bug report should be raised against it.

  • Strange problem with removing element from node

    Hi,
    I have a problem when I removed elements from a node.
    here is the code:
    String text = "123456";
    IANode nodeA= wdContext.nodeA();
    wdContext.nodeB().invalidate();
    IBNode nodeB = wdContext.nodeB();
    for(int i=0; i<nodeA.size(); i++)
    IAElement e = nodeA.getEt_Emp_RespElementAt(i);
    if (e.getID().compareTo(text)!= 0)
         nodeB.removeElement(e);
    else
    wdComponentAPI.getMessageManager().reportSuccess(e.getID() + " was not removed");
    The node A does have a row with field "ID" equals to 123456.
    When running the application, it does write that "123456" was not removed...but it removes it....In fact my table is now empty.
    How is it possible if it didn't perform the remove operation for ID = 123456 ?
    Thanks in advance.

    David,
    Because you are iterating node in wrong direction: see my reply to your post Re: Loop problem (seems that you assigns me 2 points without reading reply, and mark it as solved just because you stop solving it
    So, in example in this thread, you must iterate node B in reverse direction, get element from B and remove it from B if it has some specific ID.
    Valery Silaev
    EPAM Systems
    http://www.NetWeaverTeam.com

  • Emergency!! How to remove elements from a set? or..?

    How do I remove elements from a Set?
    If I have Set s1and s2, I want to create a new set which consist of all elements in s1 but not in the s2.
    Which means, I have to s1.union(s2) and then remove elements of s2.
    Is there any method which has this function (remove elment from a set)?
    Or is there any other better way to solve this (which doesn't have to remove anything)?
    If not, how to design a method which will do this job?
    Your help will be very much appreciated.

    Hi
    you can use method removeAll() from set
    s1.removeAll(s2);
    so s1 contains all the element not in s2.
    If you want to lef s1 unmodifyed you have to create a copy.
    Set s3 = s1.clone();
    s3.ramoveAll(s2);
    bye
    Nicola.

  • Is there a way to remove elements from an array 1 by 1?

    I have an two arrays, and they vary in size depending on a parameter set by the user (both arrays are the same size though, they both can vary in length). What I need to do, is remove elements one by one from the array, and use these as indices for another array. Basically, I built two arrays to store x-values on a graph. At the first value on the first array, I want y values on the graph to move from 0 to Y (any value). Then on the first value on the second array, I want the y values to move back from Y to 0 (creating a pulse, essentially, from the first value on the first array and the first value on the second array). By having each x value act as an indice for the y array, I belive I can acc
    omplish this (ie, y =0 up to indice 90, then y = 5, then at indice 100, y goes back to equaling 0). I know this is poorly phrased, but it's difficult to explain. If anyone could help me out, I'd really appreciate it.

    jdaltonnal,
    Note: to add an attachment based on your comment of 6/12/01 to my earlier reply, I had to go back to this 'answer' mode, which gives me the option of adding attachments.
    Per your comment, you have a sequence, so I've added a simple sequence structure and the 2nd array to provide a 250ms delay between each array output. Let me know...Doug
    Attachments:
    arrayindexplus1withseqdelays.vi ‏27 KB

  • Remove element from multi-surface

    Hi there,
    I am trying to fix some invalid multi-surface geometries that are derived from a 3D source, many of which have ORA-54514: overlapping areas in multipolygon.  I can find out which subset geometry (aka the element in this context) is causing the problem with the VALIDATE_GEOMETRY_WITH_CONTEXT function, and even extract just that element (SDO_UTIL.EXTRACT3D), but how do I remove that element from the geometry (and hopefully fix the problem)?  Is there any way to view the position of the element within the geometry in the same manner that the Extract3D function requires (i.e. 0,0,1,1,0,0,7), I can return this for the problem element but not for any of the other subset geometries.  Unfortunately I'm using FME to load the geometries and the topology validation here is not as robust as Oracle, which means I need to fix the geometries once they are loaded, but there doesn't seem to be any tools to do this?
    Regards
    Dan

    Hi Dan,
    instead of removing the offending element, how about extracting all the correct ones? Should give the same net effect, I think.
    Re FME: I find I can usually validate geometry enough that it will at least pass Oracle's Validate, but that's usually only 2D or 2D with a Z-ordinate (2.5D, as some folks call it).
    Regards,
    Stefan

  • Remove element from arraylist, jstl

    HI there,
    i use bean for an array list
    <jsp:useBean id="list" scope="page" class="java.util.ArrayList"/>
    then i add element in the list
    later i need set up a loop does the following:
    remove one element from the list and process it
    until the list is empty
    is this (romoving elment from a list) possible to be done using only jstl
    thanks

    No, it is not possible.
    JSTL is for use on JSP pages.
    JSP pages are meant for "display"
    You sound like you are doing processing - this sort of stuff more properly belongs in a java class.

  • Problem when removing elements from table after apply sort

    Hi,
    I have big problem with <af:table> and sorting.
    When I removed objects from a table without sorting, there is no problem but when I removed
    items from the table after sorting, the remain items are not correct.
    For example, i have in my table these items :
    Item AA
    Item CC
    Item ZZ
    Item BB
    Item AA
    Item BB
    Item CC
    Item ZZ
    I sort the table and i select the following Items : Item BB a Item CC
    The remains item is only Item AA, Item ZZ disappear.
    If i resort the table, the missing Item zz appear again in the table.
    Here is my jspx :
    <af:table var="row" rowBandingInterval="1" width="1050" rows="5"
    rowSelection="multiple"
    value="#{pageFlowScope.editNotificationBackingBean.ingredients}"
    binding="#{pageFlowScope.editNotificationBackingBean.ingredientsTable}"
    autoHeightRows="10" id="t2">
    <af:clientListener method="goEditRow" type="dblClick"/>
    <af:serverListener type="doubleClickOnRow" method="#{pageFlowScope.editNotificationBackingBean.handleRequestIngredientsSelectBtn_action}"/>
    <af:column headerText="#{bundle.col_fr_name}" width="240"
    sortable="true" sortProperty="name.FR_Description" id="c1">
    <af:outputText value="#{row.name.texts['fr'].value}" id="ot1"/>
    </af:column>
    In my backing bean i call this method to remove selected elements :
    public void unselectBtn_action(ActionEvent actionEvent) {
    RowKeySet rowKeySet = selectIngredientsTable.getSelectedRowKeys();
    int i = 0;
    Iterator it = rowKeySet.iterator();
    while (it.hasNext()) {
         Integer index = (Integer)it.next() - i;
    selectIngredientsTable.setRowKey(index);
    CompositionIngredient compositionIngredient =
    (CompositionIngredient)selectIngredientsTable.getRowData();
    notification.getProductDetail().getCompositionIngredients().remove(compositionIngredient);
    i++;
    selectIngredientsTable.getSelectedRowKeys().clear();
    AdfFacesContext.getCurrentInstance().addPartialTarget(selectIngredientsTable);
    Thanks in advance.

    I have made a mistake, i don't paste the right <af:table> from my jspx.
    Here is the correct one :
    <af:table var="row" rowBandingInterval="1" width="1050"
    rowSelection="multiple" id="tableSelectedIngredients"
    value="#{pageFlowScope.editNotificationBackingBean.notification.productDetail.compositionIngredients}"
    binding="#{pageFlowScope.editNotificationBackingBean.selectIngredientsTable}"
    partialTriggers="::tab_ingredients_list_expressed_per">
    <af:column sortable="true" headerText="#{bundle.col_name}" id="c5" width="180"
    sortProperty="ingredient.name.FR_Description">
    <af:outputText value="#{row.ingredient.name.texts['fr'].value}"
    id="ot18"/>
    </af:column>
    ...

  • Remove element from GUI

    Hi guys,
    I am adding elements to the gui like this:
    var myText = win.add("edittext", undefined, "whatever");
    Later in my code I need to remove this element from UI. Is it possible?

    Use the remove() method: win.remove(myText);
    In general: container.remove(child);
    You can add it later later but then, if you use the autolayout, you'll need to relayout: win.layout.layout(true) otherwise it won't show up

  • Remove element from array

    hi
    if i have an array
    eg
    int[] array = {4,2,1,2,1};
    how to i remove the index 2 from it and create a new array?
    thanks

    You can't remove the element--an array's size is fixed at creation.
    If you want a new array, create a new one that's one element smaller, then use System.arrayCopy to copy the elements you want to keep.

  • How to remove element from ByteArrayOutputStream ?

    hello frds,
    some body please help me how to remove first two elements of ByteArrayOutputStream before converting it to byte[]
    if not possible,please help me out in deleting two elements of byte[] without using arraycopy method
    thanks

    instead of writing and then removing these 2
    elements, isn't it just more logical to not write
    them in?and if you can't do that (e.g. because the code writing into the OutputStream is not under your control), then you might consider writing a decorator e.g. called "DroppingOutputStream" extending java.io.FilterOutputStream which forwards all data to the underlying stream except for the first two bytes.

  • I talked with Adobe Yesterday about removing Elements from my Mac, if there were any concerns with Lightroom 5 and Photoshop CS6

    The answered no, that all I needed to do with Elements was to drag it to the Trash. I did that. Now in Lightroom 5 do I not see Photoshop in the EDIT IN menu, all my plug-is are missing as well! Ive found two papers on the subject, one for both programs where they say to find the Lightroom fine "com.adobe.Lightroom5.plist" and a similar Photoshop fine in >user>Library>Preferences. Neither exist on my mac! Im in a process of a system search to make sure, but so far, no good!
    I'm looking for a fix, PLEASE. To stop and delete both programs, reinstall this and ALL the plug-in's isn't something I want to contemplate if I don't have to!

    Sorry Keith, I didn't look at it as a duplicate post since I initually approached it as a Photoshop issue and have since come to see it as a lightroom issue. I've subedquently found the photoshop preference file, deleted it and restarted Photoshop which recreated that file. That didn't help.
    SInce my initial concern was with Photoshop I failed to notice than none of the Lightroom plug ins were showing up. Researching that fix, what I found was essentially the same as with Photishop except the Lightroom preference file. Now I'm not finding that file but I'm doing a full system search.
    Some caveats to all of this are, the photoshop and Lightroom plug ins are the same. Theyre resident and run in CS6. Additionally in Lightroom if I go to preferances> external edit, I see photoshop and all the plug ins listed there.

Maybe you are looking for

  • BAPI to insert a new row in the AUSP table

    Hi all, I am in search of a BAPI to insert a new row in the AUSP table... with the fields of the object and characteristic values. Any inputs on this..is highly appreciable... thanks in advance... regards.. prathima.

  • Discovere lov fetch taking too much time

    Retrieving LOV taking time , how to fix it to fetch quickly .

  • Can I use aperture 3 with 2.4 ghz intel core 2 duo?

    Can I use Aperture 3 with an imac with a 2.4 ghz intel core duo processor?

  • JMSAdapter performace issue

    Hi, I've read an old thread, Re: JMS Adapter performance The author states to be able to let 700 process per minute start using JMSAdapter. I've developed a process which listen to a queue and than invoke some services. But if i put more then 50 mess

  • Blackberry 8100 pearl hard boot meltdown!

    I have a blackberry pearl 8100, t-mobile version.  I have unlocked it and switched to AT&T. I did a hardboot to refresh my memory as it was taking numerous minutes to load my applications, apon re-inserting my battery I get no boot sequence. I get a