How to compare 2 Strings that have different content in them..

I have 2 Strings:
String st1 = "1,2,3,4,6,7,9,10,11";
String st2 = "4,5,10,11";
I want to compare these 2 Strings where the result should be. Basically, any item from st2 is in st1: String res = "4,10,11";
How can I do this in an efficient way?
I was thinking of using StringTokenizer on st2 and compare each item to st1.... any help is appreciated. Thanks.

import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
* @author BADRINARAYAN
public class stringTok {
public static void main(String[] ar)
    String st1 = "1,2,3,4,6,7,9,10,11";
    String st2 = "4,5,10,11";
    TreeSet<String> value=new TreeSet<String>();
    ArrayList<String> set1=new ArrayList<String>();
    ArrayList<String> set2=new ArrayList<String>();
    StringTokenizer s1=new StringTokenizer(st1,",");
    StringTokenizer s2=new StringTokenizer(st2,",");
    while(s1.hasMoreTokens())
        set1.add(s1.nextToken());
    while(s2.hasMoreTokens())
        set2.add(s2.nextToken());
    for(Iterator it1=set1.iterator();it1.hasNext();)
        String temp1=it1.next().toString();
        for(Iterator it2=set2.iterator();it2.hasNext();)
            if(temp1.equals(it2.next().toString()))
                value.add(temp1);
    System.out.println(value);
}Edited by: badri.m on Feb 15, 2010 3:25 AM

Similar Messages

  • I have two iphones and one Apple id. Pretty confused how to have different content on them.

    Hi All,
    I have my old iphone 5s and recently I bought a iphone 6. What I want to do is to use same apple id on both of them, but I want to have different apps and media on them.
    I plan to use the iphone 5s as my 2nd phone, so I do not need same apps/music/movies/books on them. Any tips how I can keep them different? Every time I sync I have to manually select the books and music I want to have on my phone. I want to create two different profiles for my phones which will have different apps, books and music.
    I do not use icloud, so that is not a problem for me.
    Thanks,
    Sas

    Have a look here...
    setting-up-multiple-ios-devices-for-messages-and-facetime.html

  • How do i reinstall songs that have ! next to them, they're in my computer somewhere

    My Itune catalog has a number of songs with a ! next to it. I recently put some songs on a mp3 player, not all the songs that I put on the mp3 player have the !, but some do, one day there will be a ! next to a song, and then a day later gone.?? When I synch my IPOD the songs are there on my IPOD, I am unable to do anything with the selected songs, like playlist, or add coverflow, on my computer. very frustrating.  I have found the songs in my media player, but can only listen to them or playlist, then burn to disc, that really seem like the hard way to reinstall these songs. Any suggestions would help. thanks kt

    This happens if the file is no longer where iTunes expects to find it. Possible causes are that you or some third party tool has moved, renamed or deleted the file, or that the drive it lives on has had a change of drive letter. It is also possible that iTunes has changed from expecting the files to be in the pre-iTunes 9 layout to post-iTunes 9 layout,or vice-versa, and so is looking in slightly the wrong place.
    Select a track with an exclamation mark, use Ctrl-I to get info, then cancel when asked to try to locate the track. Look on the summary tab for the location that iTunes thinks the file should be. Now take a look around your hard drive(s). Hopefully you can locate the track in question. If a section of your library has simply been moved, or a drive letter has changed, it should be possible to reverse the actions.
    Alternatively, as long as you can find a location holding the missing files, then you should be able to use my FindTracks script to reconnect them to iTunes .
    tt2

  • How do I save photos that have been synced to my Ipad2, so that they do not get deleted when I sync with a different photo file on my computer.

    How do I save photos that have been synced to my Ipad2, so that they do not get deleted when I sync with a different photo foder on my computer (Pc win7).

    Place that first folder of photos that you synced to the iPad within the main folder of photos that you sync from and select them to sync again. You can place any number of subfolders within the main folder that you sync from and select those folders to sync. Just "tick"(select) the folders in the photos tab in iTunes.
    iOS and iPod: Syncing photos using iTunes

  • How to Apply adjustment layers to multiple layers that have different blending modes ...

    How to Apply adjustment layers to multiple layers that have different blending modes  and keep the colours the same as the adjusment done?
    I work in Animation painting Backgrounds.  My files are sometimes upwards to 200+ layers.
    I will use adjustment layers to quickly balance colours and constrast on top of those many many layers.
    The only way that I know of how to apply adjustment layers it to every single layer  ( by applying I mean I need to get rid of the adjustment layers because we cant use them in production but i need the new colours be applied to all layers underneath ) in a psd is to manually do it By duplicating the adjusment layer 200+ times and  then merging each layer to one of those adjustment layers so that that layer can take the adjustment layers effect permanently.
    The issue is that Within Those 200 layers I have some layers set to Multiply or OVERLAY.    IT obviously wont apply the adjustment layer properly to those layers because those layer blend mode affect the layers under them. The colour wont be the same anymore in the spots that had the multiply blended mode.
    HEres an example of a simple File.  to show what i mean.
    https://dl.dropboxusercontent.com/u/3408266/ball%20layers.jpg
    https://dl.dropboxusercontent.com/u/3408266/ball.psd
    I have 2 adjustment layers up top.  I need to get rid of them by applying them to each layer! I cannot merge any of the layers. We need all those layers for production.
    I can apply the adjustment layers manually and this works GREAT for all Layers set to normal.  THey take on the colour change just FINE.
    However, The issue is that layer 6 and layer 4 are both set to mutiply and this screws up the colour once i apply the adjustment layers to each layer manually...
    How can i apply my adjustment layers to a file like this with some layers being set to multiply while keeping the layers exactly the same configuration  and The new colour taking efffect exactly how i looks before i apply the adjustment layers?
    Now the simple solution is to merge the multiply layers to the layer that it affects HOWEVER I NEED those multiply layers to be seperate! 
    I'm assuming what I want to do is impossible? Hope this isnt confusing.  As far as i know its impossible to do what I want it to do.  but just wanted to ask and see.
    I would REALLY REALLY love to talk to a adobe programmer/ technician/pro working at adobe about this.  Theres just no way to get in touch with anyone... =(
    any thoughts ?

    Sure... if you want to put it that way. Either way its not the desirable outcome. 
    its just frustrating that theres no way to apply adjustment layers to hundreds of layers while keeping them in the same configuration ( blendmodes,  layer order ,  without merging)  while keeping the same end result.
    works great if all your layers are set to normal though..    But I really need to keep shadow layers seperately and be able to adjust on the fly aswell as apply those adjusment to all my layers.
    I suppose that just isnt possible.   I understand the math required for this would be tremendous/ complicated if something like this would ever be implemented.  Would be nice if adobe could come up with some solution to this.  Its really a huge issue in my work flow and theres no alternatives.    How else can I adjust colours to 100+ layers  with a few clicks that lets me play around the the adjustment until im happy with the outcome.    Really wish i could adjust and the quickly apply that adjustment to all my layers regardless of blend mode.   LIke If the Layers with blendmode could somehow take the properties of the adjustment layer and keep adjusting those layers undereathe on top of that blended mode that its doing...   

  • How to compare two strings whether both are equal while ignoring the difference in special characters (example: & vs & and many others)?

    I attempted to compare two strings whether they are equal or not. They should return true if both are equal.
    One string is based on Taxonomy's Term (i.e. Term.Name) whereas other string is based on String object.
    The problem is that both strings which seem equal return false instead of true. Both string values have different special characters though their special characters are & and &
    Snapshot of different design & same symbols:
    Is it due to different culture or language?
    How to compare two strings whether both are equal while ignoring the difference in special characters (& vs &)?

    Hi Jerioon,
    If you have a list of possible ambiguous characters the job is going to be easy and if (& vs &) are the only charracters in concern awesome.
    You can use the below solution.
    Before comparing pass the variables through a replace function to standarize the char set.
    $Var = Replace($Var,"&","&")
    This is going to make sure you don't end up with ambiguous characters failing the comparison and all the char are "&" in this case.
    Similar technique is used to ignore Character Cases 'a' vs. 'A'
    Regards,
    Satyajit
    Please “Vote As Helpful”
    if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

  • How to compare the programs in two different systems

    Hi,
    I have two systems say A & B and i have the program say 'Z_TESTPROG'.
    How to compare the program in two different systems.
    Regards,
    Venkat

    Hi,
    Check the version in Utilities -> version -> version management in both servers is one option.
    Another one is using SE39 transaction.
    Regards
    Manasa

  • I subscribed to iTunes Match and would like to sync my music on multiples devices that have different Apple IDs within the same iCloud family.

    I subscribed to iTunes Match and would like to sync my music on multiples devices that have different Apple IDs within the same iCloud family.
    Can someone indicate the way to proceed?
    Thanks.

    Hi,
    You can't use family sharing or multiple Apple IDs with iTunes match.
    ITunes match is only attached to Apple id that you used to subscribe.
    Jim

  • How do I get CDs that have been imported into iTunes library to sync/transfer to phone?? very frustrating and any help would be appreciated. all the material i purchased from itunes transferred fine, but CDs won't. Please help!

    How do I get CDs that have been imported into my iTunes library to sync/transfer to my iPhone?? All the material that I purchased from iTunes has transferred just fine, but although the CDs will import to iTunes, they will not sync up with my phone. How do I do this?? I am very frustrated and would greatly appreciate any help.

    In what format did you import the cds?
    I have never had an issue with this.

  • How do I combine files that have already been combined

    How do I combine files that have already been combined?

    Hi Oldshep1959
    I didn't get you ...Please Explain your workflow ...

  • HOW DO I FIND FILES THAT HAVE BEEN TRANSFERED FORM MY PC TO MY MAC

    How do i locate files that have been transfered from my PC to my new MacBook Pro

    Depends how they were transferred. If you used Migration Assistant, a new user was created. Look there in your documents folder. If you used Setup Assistant, look in your documents folder.

  • How to find all photos that have NO faces, as opposed to UNNAMED faces?

    I find that iPhoto often misses faces entirely, especially if the face is wearing sunglasses or a hat or both.  Sometimes it is rather inexplicable that it has missed a face, as the face seems obvious.
    If you use the smart album method to find all "unnamed" faces, the photos have at least one unnamed face identified.  You can then add any missed faces to those photos.
    But what about photos in which iPhoto has failed to identify the existence of even one face?  Or for that matter, if I want to see only pictures of landscapes or objects that have no people?  Does anyone have a method for finding all photos that have no faces in them at all?
    For me, the idea is to find all unidentified faces and add them.  But as I pointed out above, there may be other uses for this.
    Any ideas, anyone?
    Thanks

    Awesome !!! Thank you very much. I did not realize you could use JavaScript to code against iTunes ...
    I don't know if you have written any of these yourself, but do you know how to maybe create a smart playlist with this information via script? If not, no big deal. At least I know have something which I can use, I will just have to run it every so often.
    Thanks again for pointing me to that site!

  • How can I restore photos that have a broken red symbol below them ? Thanks.

    Help!  How do I restore photos that have a broken red symbol below them? Thanks.

    Can you post a screenshot.

  • How do I access files that have been recovered (after a Mavericks problem) with the .cca file extension

    How do I access files that have been recovered (after a Mavericks problem) with the .cca file extension

    First, to access documents you must use an app designed for that specific Document type. So Pages will not be able to open PDFs. The Documents app by Readdle can handle PDFs though. In the latter case, you'd open the app, click the menu icon at its top left, and click Open to go to your iCloud Drive. With Pages, if you had files outside the main Pages folder, click + then iCloud and navigate to the file's location.
    Matt

  • Unable to compare PDFs docs that have had security

    Unable to compare PDFs docs that have had security.
    Even when I own the documents and remove the security manually - this is a serious bug for CS5 - has anyone found a way around this?

    Did you get any error message?

Maybe you are looking for

  • Ichat video connection not working

    Hey guys how are you? The thing is that I have two Brand new 15" macbook pro and i'm trying to use them both with ichat, but the problem is that i can get connected but i cannot star a video chat, first computer stays in waiting for response and seco

  • Help with Multiple Source Video on DVD

    I am new to Premiere 9 trying to make a DVD of a birthday party with video from my Canon Vixia HF200 and a slideshow I exported from iPhoto to a m4v file.  It was my understanding from reading earlier posts I should export the instant movie I made by

  • QuickTime error 2330

    just recently, I have tried to install iTunes. It gets about 85% complete, then throws a QuickTime error. The code is 2330 and after reading for a while the solution seems to be removing QuckTime from your system. Every time I try to do this, I get t

  • MM01 tcode for SD user with restriction to SD related codes only

    Dear Experts How can we assign MM01 Authorisation for SD user with a restriction that he can access only <b><u>SD RELATED MATERIAL ONLY</u></b> ?,     Why because the material master is same for   <u>MM Module</u>   and   <u>SD Module Product Master<

  • I want to remove a dead server

    When I initially set up my mac mini I had a computer on my network i used only for data storage. I have removed this computer from the network, but the mac still continues to try to access it. I cannot figure out how to have it stop searching for and