String Comparision ---please do help me

Hai all,
I have a problem ,
1. i have an ArrayList which contains a list of all properties in the app, and an HashMap which contains the name of the file as the key and the string representation of the file as the value. i need to search the key of the ArrayList in the value of the HashMap(String representation of the file)
I have written the code as follows and its not working to get the values
Code:
HashMap hashReport=new HashMap();
               //Get the resource File Keys in the form of an ArrayList
               ArrayList rList=getResourceFiles(); // name of a function
               //Get the source Files and the String Representation of the
               //Source File in the form of a HashMap.
               HashMap sourcemap=createSourceMap(); // name of a function
               Set sourceSet=sourcemap.keySet();
               Iterator arrIter=rList.iterator();
                    while(arrIter.hasNext())
                         String arrString=(String)arrIter.next();
                         Iterator sourceIter=sourceSet.iterator();
                         while(sourceIter.hasNext())
                              String sourceStr=(String)sourceIter.next();
                              String valueStr=(String)sourcemap.get(sourceStr);
                              if ((arrString.indexOf(valueStr))!= -1)
                                   if(hashReport.put(arrString,sourceStr)== null)
                                        hashReport.put(arrString,sourceStr);
                                   else
                                        hashReport.put(arrString , ", "+ sourceStr);
please do help me in the regard.

hashReport.put(arrString , ", "+ sourceStr);This does not append sourceStr to the existing value. It just puts sourceStr, with a comma in front of it, in hashReport, overwriting any value that was already associated with arrString. If you want to append, you'll need to save the value from when you checked it earlier:
if(hashReport.put(arrString,sourceStr)== null)By the way, that kinds of make the following statement kind of extraneous. You only need to do extra work if the result of the first put is not null.
The approach you're taking may not be ideal anyway. Rather than creating long comma-delimited Strings, another approach you could take is to use Lists as the values of the result map, like this:
if ((valueStr.indexOf(arrString))!= -1) {
  List val = hashReport.get(arrString);
  if (val == null) {
    val = new ArrayList();
    hashReport.put(arrString, val);
  val.add(sourceStr);
}

Similar Messages

  • String Comparision in XSLT Mapping

    HI All,
    Can any one suggest me to compare the two strings in XSLT mapping.Please let me know is there any string comparision function in xslt?
    Thanks
    Pullarao

    Hi Pullaro!
    It depends what you want to do with the comparison
    E.g. you can use a simple xsl-if Tag to compare a value
    and then take action.
    If your XML looks like this:
    <root>
      <child><b>value1</b></child>
      <child>value2</child>
    </root>
    you can make an expression like this and take action on it:
    <xsl:if test="<b>//child = 'value1'</b>">
        <i>.. Do what you want to do here..</i>
    </xsl:if>
    With kind regards
                 Sebastian

  • Please! help me with this wrong code, where is mistake

    please! help me with this wrong code, where is mistake?
    import java.util.Stack;
    public class KnightsTour {
    Vars locs[];
    private int size, max=1, d=0, board[][];
    public KnightsTour(int x,int y, int newSize)
         size=newSize;
         locs=new Vars[size*size+1];
         for(int n=1;n<=size*size;n++)
              locs[n]=new Vars();
         board=new int[size+1][size+1];
         for(int n=1;n<=size;n++)
              for(int n2=1;n2<=size;n2++)
                   board[n][n2]=0;
         locs[max].x=x;
         locs[max].y=y;
         locs[max].d=1;
         board[x][y]=max;
         max++;
    class Vars{
         int x;
         int y;
         int d;
    public void GO()
         int n=0;
         while(max<=size*size)
              n++;
              d++;
              if(d>8)
                   max--;
                   board[locs[max].x][locs[max].y]=0;
                   d=locs[max].d+1;
              move();
         printBoard();
    public void move()
         int x=locs[max-1].x, y=locs[max-1].y;
         switch(d)
         case 1:x--;y-=2;break;
         case 2:x++;y-=2;break;
         case 3:x+=2;y--;break;
         case 4:x+=2;y++;break;
         case 5:x++;y+=2;break;
         case 6:x--;y+=2;break;
         case 7:x-=2;y++;break;
         case 8:x-=2;y--;break;
         //System.out.println(" X: "+x+" Y: "+y+" |"+max);
         if((x<1)||(x>size)||(y<1)||(y>size)){}
         else if(board[x][y]!=0){}
         else
              locs[max].x=x;
              locs[max].y=y;
              locs[max].d=d;
              board[x][y]=max;
              max++;
              d=0;
              //printBoard();
    public void printBoard()
         for(int n=1;n<=size;n++)
              for(int n2=1;n2<=size;n2++)
                   if(board[n2][n]<10)
                        System.out.print(board[n2][n]+" ");
                   else
                        System.out.print(board[n2][n]+" ");
              System.out.println();
         //System.out.println();
         System.out.println();
         public static void main (String[]args){
              KnightsTour k = new KnightsTour(1,1,8);
         }

    public class KnightsTour {
        Vars locs[];
        private int size,  max = 1,  d = 0,  board[][];
        public static void main (String[] args) {
            KnightsTour k = new KnightsTour (1, 1, 8);
            k.GO ();
        public KnightsTour (int x, int y, int newSize) {
            size = newSize;
            locs = new Vars[size * size + 1];
            for (int n = 1; n <= size * size; n++) {
                locs[n] = new Vars ();
            board = new int[size + 1][size + 1];
            for (int n = 1; n <= size; n++) {
                for (int n2 = 1; n2 <= size; n2++) {
                    board[n][n2] = 0;
            locs[max].x = x;
            locs[max].y = y;
            locs[max].d = 1;
            board[x][y] = max;
            max++;
        class Vars {
            int x;
            int y;
            int d;
        public void GO () {
            int n = 0;
            while (max <= size * size) {
                n++;
                d++;
                if (d > 8) {
                    max--;
                    board[locs[max].x][locs[max].y] = 0;
                    d = locs[max].d + 1;
                move ();
            printBoard ();
        public void move () {
            int x = locs[max - 1].x, y = locs[max - 1].y;
            switch (d) {
                case 1:
                    x--;
                    y -= 2;
                    break;
                case 2:
                    x++;
                    y -= 2;
                    break;
                case 3:
                    x += 2;
                    y--;
                    break;
                case 4:
                    x += 2;
                    y++;
                    break;
                case 5:
                    x++;
                    y += 2;
                    break;
                case 6:
                    x--;
                    y += 2;
                    break;
                case 7:
                    x -= 2;
                    y++;
                    break;
                case 8:
                    x -= 2;
                    y--;
                    break;
    //System.out.println(" X: "x" Y: "y" |"+max);
            if ((x < 1) || (x > size) || (y < 1) || (y > size)) {
            } else if (board[x][y] != 0) {
            } else {
                locs[max].x = x;
                locs[max].y = y;
                locs[max].d = d;
                board[x][y] = max;
                max++;
                d = 0;
    //printBoard();
        public void printBoard () {
            for (int n = 1; n <= size; n++) {
                for (int n2 = 1; n2 <= size; n2++) {
                    if (board[n2][n] < 10) {
                        System.out.print (board[n2][n] + " ");
                    } else {
                        System.out.print (board[n2][n] + " ");
                System.out.println ();
    //System.out.println();
            System.out.println ();
    }formatting ftw.
    If you call GO () you get in an infinite loop. max gets decreased, and it loops while max is smaller then or equal to size * size. Is your looping logic correct ?

  • String comparision using tokens (challenging question)

    Hello, everyone.
    i am having a problem with string comparision.
    for example, the input file is:
    each line is an input line (string)
    1)a x
    2)b c x
    3)a b x
    4)a b y
    5)a b c x
    in above example a,b,c,x,y are strings(tokens)
    in above example
    line 1 ,3,5 has token "a" common and class "x" is also common
    if this condition is satisfied,
    line 1 should be send to general file (output file 1) and
    line 3 and 5 should be send to specific file (output file 2)
    rest of the lines should be send to third file.
    remember in line 4, token "a" is same when compared with line1
    but it has a different class (y) .this line will go the third file. this is where line 3 and 4 differs.
    i have read this file into an string array.
    how to proceed further.
    i am new to java programming.
    cheers in advance.

    Well, first off, I'm assuming that you keep the first string as the first token and the class name as your last token, then you tokenize everything using StringTokenizer. the code would look something like this. You could also use countTokens() to know how many tokens are in a tokenizer.
    My approach would be the following:
    1. Create an array of Strings to hold each line (you already did that)
    2. Go through the array, one line at a time, tokenize the String, figure out the first and last tokens
    3. Write it to the corresponding file.
    The code would be something as follows
    String ClassToLookFor, StringToLookFor; // holds which class and first string to look for
    String firstToken, lastToken; //used in checking each element with first one
    boolean firstFound = false;  // First instance of Class name and first thread combo found
    public static void main(String args[])
    StringTokenizer tokenizer;
    int tokenizerLength;
    // read in array of Strings, store it into lines or something
    int endOfRun = lines.length;
    for (int i = 0; i<endOfRun; i++)
    tokenizer = new StringTokenizer(lines);
    tokenizerLength = tokenizer.countTokens();
    if(!firstFound)
    // store the information (StringToLookFor and ClassToLookFor) and write the line to the corresponding file
    else
    firstToken = tokenizer.next();
    int runThru;
    while(runThru < (tokenizerLength - 2)) {tokenizer.next();} // going to the last token
    lastToken = tokenizer.next();
    if (firstToken.equals(StringToLookFor) && lastToken.equals(ClassToLookFor))
    {write lines[i] to second file}
    else
    {write lines[i] to third file}
    hope that helps ...

  • My itunes library is empty but i want to upgrade my ipod without losing my music. how can i do this? please someone HELP!!!

    i recently got a new laptop so my itunes library is empty but i want to upgrade my ipod without losing my music. how can i do this? please someone HELP!!!

    but i got music from my old laptop and my little brothers laptop so basically its no way i can take whats already on my ipod and put it on my computer and drag and drop it to my new itunes library

  • Hey iphone an iphone 3g and i only have about 13 apps and the yellow bar on itunes for my phone is way to big i deleted all my photos all my music every thing i ryed restoring ans all it still takes up space for sum reason ?? please someone help me

    hey iphone an iphone 3g and i only have about 13 apps and the yellow bar on itunes for my phone is way to big i deleted all my photos all my music every thing i ryed restoring ans all it still takes up space for sum reason ?? please someone help me

    If Other (the yellow bar) is too big something is corrupted.  The only solution (that I know of) is to restore from your most recent backup using iTunes (see http://support.apple.com/kb/ht1766).

  • Setup problem please anyone help ~~ me !!!

    i was trying to setup adobe photoshop and i clicked setup.exe (file picture display like as a white paper) and it told me to choose application. so i dont know how to change or choose which program .. please anyone help me out on this..

    Photoshop is an application that must be purchased (not available via a download) and isn't cheap.
    You must purchase the OS X (Tiger compatible) version of Photoshop.
    Check Apple's online store under software or do a Google search.

  • My phone 5s did the new update and will not come back on. I already tried hard reboot still won't work. Been over a hour now. Please someone help I need my phone.

    My phone 5s 16gb gold did the new update and will not come back on. I already tried hard reboot still won't work. Been over a hour now. Please someone help I need my phone.   This phone is not even 6 months old been in case no scratches. This is driving me crazy.

    Connect your phone to a computer and restore your software using iTunes.

  • Ever since the new update, my Ipod won't sync. Starts to sync but then goes back to connected eject before disconnecting. Still won't transfer songs even after being restored. Restored fine. But now I've got nothing on it. Please god help!

    For awhile, since the newest update, I'd noticed when charging the ipod (classic) that it stopped going to the charging screen and would stay on the  Connected: Eject before disconnecting' screen. But, y'know, didn't matter to me, it still charged... until today when I tried to add music. Tried it many times, reset it... STILL wouldn't transfer songs... It would 'say' it was syncing, but then suddenly stop and stay on the same Connect: please eject before disconnecting' page. I did a couple of times get a message about scanning it but, after restoring that never popped up again...
    So, I do a system restore on it and ofcourse THAT works, but it STILL won't sync! So, now I've got an ipod with no music that won't sync and because it's all gone on there, I'm not sure how to back up my stuff (should I need to re-install iTunes... Though I doubt it'd work...)... So, yeah, I tried a different cable too, still no luck...
    There has GOT to be some way to fix this!
    Please somebody help me out! I so freaking appreciate it you have NO idea!

    I think the problem is that the iPod got set to Manually manage music and videos.  It needs to be set up for automatic syncing again.  Just unchecking that Manually manage music and videos setting does not do it.
    In iTunes 12, select the iPod in iTunes (using the device button), so that you see the iPod's "management" screen.  In the sidebar (along left side of screen), there are two headings (Settings and On My Device).  Under Settings, click on Music.  To the right, you see the iPod's Music screen, where you tell iTunes how to sync songs to the iPod.
    Check the box at the top for Sync Music.  That turns ON automatic syncing for music.  Below that, choose the option to sync Entire music library (assuming your music library fits completely on your iPod).  Otherwise, you can choose the option to sync Selected playlists, artists, albums, and genres and make your selections below.  Then click Apply.

  • HT6154 Can someone please just help me figure out how to update this stupid phone without losing anything? I somehow have more than one Apple ID on this,but I just want my music and my pictures to stay and I'm terrified of losing these things.

    Can someone please just help me figure out how to update this stupid phone(iPhone 4)without losing anything? I somehow have more than one Apple ID on this,but I just want my music and my pictures to stay and I'm terrified of losing these things. I have a lot of music from old CDs on here,and for some reason I can't even transfer them manually onto my computer. I'm not tech savvy whatsoever. Someone please help,having my music is the the whole reason I still have this phone.

    First read about back http://support.apple.com/kb/ht1766
    Then  read on how to transfer photos to your computer http://support.apple.com/kb/ts3195
    Then
    UPDATING iOS
    Over the air updating of iOS needs iOS 5 or later so unless you have iOS 5 or later you will not see updating in setting
    The following link explains how to update http://support.apple.com/kb/HT4972
    This link explains how to update using wireless http://support.apple.com/kb/HT4623
    This explains how to transfer purchases to your computer http://support.apple.com/kb/ht1848

  • 25k Limit in iTunes Match? PLEASE SOMEONE HELP!

    I have been collecting music steadily for almost 25 years now. In 2009, before selling them on eBay, I had over 2,000 CDs in my collection. At that point I ripped them all into iTunes and stored the files on an external drive. I have continued to steadily collect music since then...ripping CDs borrowed from friends, free (and legal) downloads, bit torrent concert DLs from places like Archive.org and yes, many purchases from the iTunes store. 
    Currently I have 45,962 songs, weighing in at just shy of 264 GB. I have a 260 GB iPod Classic which I LOVE, but unfortunately outgrew quite some time ago (260 actually means 241 or so). Needless to say, I have very eclectic taste in music, and one thing I LOVE to do is listen to my ENTIRE collection on shuffle. I also have 30-or-so playlists which I add tracks to as they come up on shuffle. Once I reached the limit on my iPod, I set it to only sync checked songs and began systematically unchecking songs I don't like or like "not-as-much." This worked fine for some time, but I am all out of files to "uncheck" (I tend to only buy music I like). Additionally, I now need to quickly uncheck a bunch of files every time I get new music, if I want to listen to it on my iPod. For some time I held onto some hope that Apple would put out a 320 GB Classic, but sadly that is never going to happen.
    I have a 16 GB iPhone 5, but storing music in that would be ridiculous.
    Since getting my Mac, I have a renewed passion for my iTunes library and music collection (not-so-fun with semi-functional PCs). I am finally able to organize my library like I like to, and would LOVE to be able to access it remotely.  A friend recently told me to check out iTunes Match, which reads like Storybook Fantasy in its description. Imagine my disappointment to learn that there's a 25k song limit! Tracks purchased from iTunes don't count toward the 25k, but I am not about to start re-buying 90% of my music just to use iTunes Match. I purchased a 3T WD My Cloud, hoping that would solve the issue, but apparently Apple's proprietary restrictions prevent the iTunes server from streaming remotely on my device using this service.
    I read here in the forums, someone's instructions on how to essentially have TWO libraries, scaling one down to 25k...WHAT? I'd be better off just sticking with my Classic, which fits around 33k songs!
    PLEASE SOMEONE HELP...Does anyone out there know of any way to accomplish what I want to do? I want to be able to access and play my entire music library (about 46,000 songs and growing), through iTunes (playlists, play count intact), through an app on my phone.
    I own the following equipment:
    (Late 2014) 13" MacBook Pro with Retina Display (running OS Yosemite)
    260 GB iPod Classic
    16 GB iPhone 5 (running iOS 8.1.2)
    WD 3T My Book
    WD 3T My Cloud
    Thank you. Please help. Thank you.
    <Edited By Host>

    Jimzgoldfinch wrote:
    Why is it nonsense?
    iCloud Drive storage is not the same as iTunes match. ITunes Match does not store your music but matches with what's on the Apple servers and uploads non matched music.
    jim
    Where shall I start?
    The music that is uploaded to iTunes Match (as you mentioned) is stored in iTunes Match. If it is not then where exactly is it?  User uploaded tracks are subject to a 25,000 limit. There is no limit to the amount of iTunes purchased music.
    All music stored in Match (either uploaded by you or purchased from iTunes by you) is available for streaming or download to an IOS or OSX device (Windows may be download only)
    It's nonsense because it is almost entirely incorrect.

  • Would like to trace my ipod touch because I was robbed. I would find it please. need help from you guys. Not because I am able to get another. Thank you.

    would like to trace my ipod touch because I was robbed. I would find it please. need help from you guys. Not because I am able to get another. Thank you.

    - If you previously turned on FIndMyiPod on the iPod in Settings>iCloud and wifi is on and connected go to iCloud: Find My iPhone, sign in and go to FIndMyiPhone. If the iPod has been restored it will never show up.
    iCloud: Find My iPhone
    - You can also wipe/erase the iPod and have the iPod play a sound via iCloud.
    - If not shown, then you will have to use the old fashioned way, like if you lost a wallet or purse.
    - Change the passwords for all accounts used on the iPod and report to police
    - There is no way to prevent someone from restoring the iPod (it erases it) using it unless you had iOS 7 on the device. With iOS 7, one has to enter the Apple ID and password to restore the device.
    - Apple will do nothing without a court order                                                        
    Reporting a lost or stolen Apple product                                               
    - iOS: How to find the serial number, IMEI, MEID, CDN, and ICCID number

  • I have a problem in my iphone 4 with wi-fi after update to IOS6 please can help my how can solve this problem?

    I have a problem in my iphone 4 with wi-fi after update to IOS6 please can help my how can solve this problem?

    Nope
    One needs to press the home and sleep / wake keys together for the phone to reset
    The other thing I could recommend
    Let the battery run out and the phone completely "die"
    It may take a day or two with it not being used
    Then plug it in to charge and see if there is any change in behavior
    If you cannot get this to work - you may need to bring it to an Apple store

  • I need to reformat my computer and I will loose my itunes, How do I go about getting all my apps free and paid back when I reinstall everything (Please someone help)

    I need to reformat my computer and I will loose my itunes, How do I go about getting all my apps free and paid back when I reinstall everything (Please someone help)

    Have you failed to backup your computer?
    If so, then you will have to redownload.
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • I switched phone with my brother and i could sucessfully restore everything to the new phone except my imessages. how can i restore them? and why this phone doesnt let my use my number, just my apple id for immesage/facetime? please somebody help me!!

    after restoring all my stuff to the new phone, i wanted to see my messages but i discovered that all my imessages are missing. i checked in settings and i dont know why but the new phone doesnt let me use my phone number for imessage or facetime, instead it's using just my apple id. any idea how can i switch to the phone number again? in my old phone i used both my number and email for imessages, so i think maybe thats why i cant see my immessages now. please somenone help me!! thank you so much

    Hi Katrina - I hear what you are saying about the problems. I've been using a BB Pearl here in Canada since January and I had the same problems with PocketMac from the start. iCal dates getting strangely duplicated after syncing and contacts in AddressBook groups getting listed twice on the BB. The only solution I used was to have the Mac always override the BB when syncing. NOt perfect but for me it was the simplest way to ensure the consistency of the data and my own sanity.
    If anyone has a better solution that actually allows a clean sync I'd love to hear it.

Maybe you are looking for