How to search and delete repeated elements in a vector

Hi again,
In a class of my application, it needs to check in a vector (A), if there are repeated elements, if it founds one, then it is replaced for a *. then the elements different from * are copied into a new vector(Aa). the code is the following:
//here are defined the components Textfield, etc
public void Bconj_Action(Object target)
          int idx = 0;
          int tokenCount;
          String var="";
          String var2="";
          String A[] = new String [50];
          String Aa[] = new String [50];
          String message = (TxtA.getText());
          StringTokenizer st = new StringTokenizer(message,",");
          tokenCount = st.countTokens();
          while (st.hasMoreTokens())
               A[idx] = st.nextToken();
               idx++;
          //Recorre vector A en busca de repetidos     
          for(int n=0;n<tokenCount-1;n++)
          for(int m=n+1;m<tokenCount;m++)
          if (A[m]==A[n] && A[n]!="*")
               A[n]="*";
          //Recorre nuevamente el vector A buscando los diferente a * que seran copiados al vector Aa
          int o = 0;
          for (int n=1;n<tokenCount;n++)
          if(A[n]!="*")
          Aa[o]=A[n];
               o++;
          for (int i=0;i<tokenCount; i++)
                    if (i==0){
                    var=Aa;}
                              else{
                              var = var + "," + Aa[i];}
               TxtA.setText("");
               TxtU.setText(var);
when I run it, and I enter to the prog 1, it don't show me nothing, when I enter 1,1 it shows me 1,null and so on.
do you have any ideas of what is happening.
Thanks in advance.

Two things I would point out to you:
Its possible that the way you are comparing the Strings is causing a problem for you.
if (A[m]==A[n] && A[n]!="*")
A[n]="*";
}A[m] and A[n] are two Strings so you should compare them using
A[m].equals(A[n]).So the if statement should look like this:
if (A[m].equals(A[n]) && !A[n].equals("*"))
A[n]="*";
}And second:
When you copy the unique elements over to array Aa you may be copying less that tokenCount elements. You are actually copying o elements.
The final for loop could be modified like this:
for (int i=0;i<o; i++)
if (i==0){
var=Aa;}
else{
var = var + "," + Aa[i];}
TxtA.setText("");
TxtU.setText(var);
} Thus it prints only the unique elements found rather than the whole array which may contain nulls.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How to search and delete an email from the mailbox

    hi,
    have a hybrid scenario, exchange 2013 and office 365
    what command should I use to search and delete an email from the organization mailbox i.e. I do not want that email to be in any users inbox.
    I have tried this command but it does not work, it says search-mailbox is not recognized as the name of the command let.
    Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery 'Subject:"Download this file"' -DeleteContent
    kindly assist.
    Kind Regards, Khuzema R.

    Hi Khuzema
    This can be accomplished by search-mailbox command
    First you need to create a new role group
    To Create –  New-RoleGroup “Mailbox Import-Export Management” -Roles “Mailbox Import Export”
    Then add the user to the group
    To Add user – Add-RoleGroupMember “Mailbox Import-Export Management” -Member Administrator
    Search the mailbox
    get-mailbox -ResultSize unlimited -IgnoreDefaultScope | search-mailbox -SearchQuery ‘Subject:”virus infected”’ -LogOnly -TargetMailbox administrator -TargetFolder filter -LogLevel Full
    Now we need to run the below command to search the infected emails and delete all of them in the whole organization
    get-mailbox -ResultSize unlimited -IgnoreDefaultScope | search-mailbox -SearchQuery ‘Subject:”virus infected”’ -TargetMailbox administrator -TargetFolder filter -deletecontent -LogLevel Full
    Also you can do a message tracking with the subject and delete them
    Get-ExchangeServer | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true} | Get-MessageTrackingLog -Messagesubject “Virus Infected” | Select-Object Timestamp,ServerHostname,ClientHostname,Source,EventId,Recipients
    | Sort-Object -Property Timestamp
    I have written a blog with regards to the same. You can always refer this which might mostly  help you in your scenario
    http://exchangequery.com/2014/10/16/steps-to-delete-circulated-suspicious-emails-with-search-mailbox/
    Thanks 
    Remember to mark as helpful if you find my contribution useful or as an answer if it does answer your question.That will encourage me - and others - to take time out to help you Check out my latest blog posts on http://exchangequery.com Thanks Sathish
    (MVP)

  • 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);
    }

  • How to search and remove all exact words

    How to search and remove all exact words, I have tried adobe 11 Pro and I still need to know how to do this

    That works well for replace or deleting one at a time, I need to search the doc and delete all found and not change formatting
    Thank you for your help

  • How to archive and delete messages in SXMB_MONI

    Hi all,
    We are working on SAP XI Development environment wherein we have File to IDoc scenario running twice daily and creating many messages.
    How to archive and then delete these messages ?
    Does accumalation of past messages affect the speed and performance of the system?
    Thanks in advance.
    Ajay

    Ajay,
    For step by step procedure of how to archieve and delete messages in XI go through the urls:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/402fae48-0601-0010-3088-85c46a236f50
    Delete Messages SXMB_MONI
    http://help.sap.com/saphelp_nw04/helpdata/en/0e/80553b4d53273de10000000a114084/frameset.htm
    Too many questions on Archive/Delete messages.
    ---Satish

  • How to find and delete duplicate photos in photo app

    how to find and delete duplicate photos in photo app

    Photos has no built-in tools to screen the library for duplicates. It relies on the warning on import, that should prevent you from importing duplicates.
    Once duplicate shave been imported, delete them manually, or use third-party tools.
    For example, these new apps claim to work with Photos:
    Power photos:  Fat Cat Software
    Duplicate annihilator: Brattoo Propaganda Software - Products
    PhotoSweeper: http://overmacs.com/photosweeper.html

  • I am trying to figure out how to cut and paste in elements 11

    I am trying to figure out how to cut and paste in elements 11

    On picture A, use one of the selection tools (e.g. selection brush, lasso tool, etc.) to select the object
    Go to Edit menu>copy to place the object on the clipboard
    Open picture B
    Go to Edit menu>paste
    Get the move tool out of the toolbox, and position the object and resize with the corner handles of the bounding box

  • Purchased photoshop elements 12 and premiere elements 12. downloaded and installed photoshop elements12 but cannot find how to download and install premiere elements 12

    After I purchased pselements 12 and premiere elements 12 I downloaded and installed pselements 12 but I cannot find how to download and install premiere elements 12 because that window has disappeared and I can't get back to it. How do I download and install premiere elements 12? where is it? how can I find it?

    rachif
    I am assuming that the purchase and download is from Adobe. You should find the information that you seek under My Orders at http://www.adobe.com after you sign in (as per John's link).
    However, if you have difficulties in going that route, please contact Adobe via Adobe Chat to discuss your order under the topic of Orders, Refunds, and Exchanges. To do that, click on the following link, and, when it opens, make sure that the topic is set at "Orders, Refunds, and Exchanges", click on the statement "Still need help? Contact us." to bring up the Adobe Chat.
    Contact Customer Care
    Please let us know the outcome.
    Thank you.
    ATR

  • How to create and delete an Endeca application in Windows

    HI,
    can you please help me in ,
    how to create and delete an Endeca application inWindows machine not in Linux Machine.
    Thanks.....

    Hi,
    Steps to create an Endeca Application are clearly given in Getting Started Guide.
    http://docs.oracle.com/cd/E38680_01/Common.311/pdf/GettingStarted.pdf (Chapter 6 : Deploying a Reference Application)
    If you want to create an endeca application so as to integrate with Product Catalog system such as ATG using ATG 10.1.1 or above , then create an endeca application using the discover-data-catalog-integration reference application. Steps for doing this are documented in ProductCatalogDTGuide
    http://docs.oracle.com/cd/E38679_01/ToolsAndFrameworks.311/pdf/ProductCatalogDTGuide.pdf (Deploying the Product Catalog Application)
    To delete an Endeca Application that you have created in Windows/linux
    1. Navigate to the control directory of the application that you want to remove and execute the script
    runCommand.bat --remove-app (Removes the provisioning information with EAC admin console)
    2. Remove the instance configuration files for the application using the emgr_update command line utility
    emgr_update.bat host localhost:8006 app_name My_app action remove_all_settings prefix My_prefix
    3. You can then explicitly delete the directory in the Endeca_apps directory where you have initially created your application.
    If you are using discover-data-catalog-integration, you can remove the CAS Record Store Instances by navigating to CAS/bin directory and executing
    ./component-manager-cmd.sh delete-component -n {YOUR_APP_RECORD_STORE_NAME}
    Thanks,
    Shabari

  • How to insert and delete fragments by clicking a button and how to script it?

    I have a  question on livecycle. I am collecting the inventor information as a bunch of text fields, each asking for a certain details. Please see below
    Now I have grouped them all in to one fragment called inventordetails and saved as .xdp file, so I could reuse this entire block. I want to add a button underneath this block, “ADD MORE INVENTORS” and when clicked this will insert another block and so forth and so on. However I was not sure as to how to insert and delete a fragment. Do  you think you can help with this? I appreciate any help in this regard.
    Best
    Subashini

    1.       I have a subform1 which is flowed
    2.       I have subform2 inside subform1 which is positioned
    3.       Inside subform2 I have two buttons 1. ADD INVENTOR 2. DELETE INVENTOR
    4.       Also inside subform1 I insert a fragment called inventor
    Now I want to script the buttons so that when clicked the inventor fragment either gets inserted again or deleted.
    I greatly appreciate any help in this regard.
    Best
    Subashini

  • In Pages, how to search and replace text involving invisible characters?

    In Pages documents, how to search and replace text involving invisible characters, colors and font sizes—a task which is so easy in Mircosoft Word?

    I read that an older version of Pages allowed users to enter special characters in the search/replace fields, but this did not work for me.
    Here: http://www.macworld.com/article/1156533/pagesspecialcharacters.html
    I still am looking for a way to do this.

  • 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 do I search and return multiple elements of array quickly (like Matlab find)?

    Hi, I am a fairly experienced Labview programmer, and I have always wondered if there is a way to quickly search arrays for multiple elements that meet a selection criteria, equivalent to the Matlab find command.  While my inability to do this in Labview has always bugged me, I now have an application that requires this ability and I need to find a solution. 
    The fastest way that I have found to do this in labview is to perform comparisons on vectors of data, and then use the resulting Boolean vector to parse the array using a for loop and shift registers.  I have attached a vi snippet of a benchmarking vi for one of the simple searches I need to do.  On my laptop this search takes about 600ms.  In comparison, the equivalent in Matlab:
    newArray=oldArray(find(oldArray(:,4)./oldArray(:,2​)>1.5),;
    executes in about 1.2ms.  So, the way that I am doing this in Labview is only 400 times slower
    Needless to say, I need to do these types of searches many many times, and those 599 extra ms start to add up pretty quickly!
    Thanks for your help,
    Aaron    
    Solved!
    Go to Solution.
    Attachments:
    benchmarkSearch.png ‏641 KB

    Hi Aaron,
    the slowest part is probably the "build array" node in the loop.
    Try this:
    Define an array of same size as input data (or simply use a copy of it) and wire that to the shift register. Keep a counter of found rows in the loop. Use IndexArray and ReplaceArraySubset in the loop to move the found rows to beginning of array (overwrite "bad" rows). After the loop simply ReshapeArray to the number of found rows...
    Sorry, don't have LV(2009) at hand to edit your snippet.
    Message Edited by GerdW on 11-20-2009 08:27 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Search and Delete a specific record from a CSV file

    Hi All,
    I am new to java . I want to search for the records from CSV file and delete the row form the file.
    Below is my Sample .csv
    100||a100||1b100
    200||b200||dc300
    200||bg430||ef850
    400||f344||ce888
    Now I need some help in below requirements.
    1.How to delete a record having value 200 and b200?
    2.If record already exists how to update the existing record with new values?
    Please share your ideas or give me some code snippet..
    Thanks in Advance

    In that case Do i need to write the entire contents of my file to a hash table(sumthng like this) and modify the Second row in my case with the new values..
    is it possible??I would have done like this (though there maybe better methods)
    1- create a class representing the record.
    class Record{
          String field1;
          String field2;
          String field3;
          // and so on....
          //setters
          public void setFeild1(String str){
              field1=str;
          // and so on....
          //getters
          public String getFeild1(){
              field1=str;
          // and so on....
          public String toString(){
               return(field1+"||"+field2+"||"+field3);
    }//end class2- then create an ArrayList meant to have objects of this class (Generics).
    3- read from the file , create a new Record Object and add that to the ArrayList
    4- perform operations on the ArrayList (you can add new records, and delete record, update......)
    5- write the record back to file using 'toString()' method.
    is there ne sample code available for thisdon't know, but you rarely get full code on forums.....outline given can be followed
    Thanks!
    Edit: It appears that 'r035198x' and me have the same point. This shows that this methodology is almost a standard way( if we ignore the Random access files.....)
    Edited by: T.B.M on Jan 13, 2009 2:39 PM

  • How to Search for a specific element in a MultiGraph?

    Hi there
    Im trying to implement a Multigraph ADT in Java. Multigraph is a graph that has multible edges connecting a node. I assume you all know what a Graph ADT looks like.
    So i think ive got all the basic methods functions of a normal graph/mulitgraph and now i want to search for a element in it
    The question is how will i so that?
    Do i use a breadth first search?
    But i thought a BFS traverses all the elements in a graph? And how can i use a BFS to search for a specific element in a graph?
    Thanks

    Hey there
    thanks for your reply but i still some query.
    I thought of doing that but i want to remember the nodes i revisted to get to the target (not all - but the quickest route to that node)
    My design so far is:
    have 3 Interface namely Graph, Node & Edge.
    Classes will inherit those interface to provide the actual implementation as i want the details/coding to be abstract meaning i can give many different way of implementations.
    The graph class will add nodes & edges where when adding edges, edge will store 2 nodes in it respectively source & destination nodes.
    Both Node & Edges will be stored in graph using some data structures atm (arrayList i presume)
    My Design is that i want to (my aim of the task of searching) search for a node in the multigraph by inputting (maybe 2 nodes) into method - start node target node! The method should return a list of nodes to get to the target node.+
    So so far i have this wee algorithm in mind:
    +1. Input start + target node as parameters+
    +2. Use BFS to search the graph+
    +3. When reached target node - halt+
    +4. return the list of nodes that visited to get there (but not all - only the precise & fastest)+
    So will that work?
    If so how do i go about doing implementation?
    Thanks

Maybe you are looking for

  • Error while activating XI App:  references the inactive object

    Guys, I am getting this error when I am activating my XI application . <i><b>Activation of the change list canceled Check result for Message Mapping Stockquote_Request_Map_01 | http://sapteched/XI/sessionid_XI251/inb/student_01:  Object Message Mappi

  • "Adobe Media Core CS5.5 has stopped working"

    Whenever I try to encode using the Quicktime-H.264 codec in Adobe Media Encoder, I get a crash that states "Adobe Media Core CS5.5 has stopped working". Also I have tried to encode using this codec directly within Premiere Pro with the "Export" butto

  • Canon IJ Network Scanning Utility not showing up in Menu bar

    Hi, I recently performed an erase and install of my Mac. I then used Migration Assistant to restore my data. I have a Canon MP620 Wireless Printer. I noticed that the Canon IJ Network Scanning Utility is not showing up in the menu bar. How do I get i

  • Can Acrobat be remote controlled via COM/CORBA?

    I am somewhat familiar with handling OpenOffice using UNO, Microsoft's office software with COM and then there is CORBA, of course. My question is: To what extent is Acrobat capable of being "handled" in such fashion? My GUI application creates filla

  • Process flow run success but underline mapping sql still running

    We have mapping A and B in process flow. We configured Enumerated Condition (success) in mapping A to kick off mapping B after A is success. But the underline SQL in A took long time to finish therefore mapping B starts before data loading is finishe