简体   繁体   中英

How to choose the correct splitted string if it match the end of original String is it possible?

I'm having a hard time to find a solution for this issue:

// look we have two strings that have the same ending " day "
       String days[] = new String[] {"Sunday", "Monday"};
   // but here i want nday to be choosen for Monday
   // and day for Sonday
   String splDay[] = new String[] {"Mo","Sun","day","nday"};

What will happen now is that the endsWith Method will pick " day " instead of " nday "

for (String splt: splDay)
{
    if (days[0].endsWith(splt))
    {
        //now it will pick
        Toast.makeText(this , splt , Toast.LENGTH_SHORT).show();
        break;
    }
}

Keep in mind that I'm dealing with 1000 of splitted words and I want to pick the correct one that I meant it to be for the original word? Is it possible?

i had to do this idea :

String days[] = new String[] {"Sunday", "Monday"};

String splDay[] = new String[] {"Mo","Sun","day","nday"};

String AnswersArray[][] = new String[][]{  {"Sun","day"} ,{"Mo", "nday"}  };

it's not professional way but what can i do.. that's all i got.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM