简体   繁体   English

从 Map 中查找部分键及其值<String, String>在 Java 中

[英]Find partial key and their value from Map<String, String> in java

I've this map key value pair as :我将此地图键值对设为:

{$skip=28, $landingPageURL=https://www.example.com, $gtmCount=gtmMPCL, $url=mpclProd, $trackingJson=mpclNonAmpTracking.json, $portalCD=portal_CD_MPCL}

and I need to findout the key as $landingPageURL?utm_medium=lp_automation from the above map.我需要从上面的地图中找出作为 $landingPageURL?utm_medium=lp_automation 的键。 So, my final output should be for **$landingPageURL?utm_medium=lp_automation** as https://www.example.com?utm_medium=lp_automation (because $landingPageURL is replaced with above map).所以,我的最终输出应该是**$landingPageURL?utm_medium=lp_automation** as https://www.example.com?utm_medium=lp_automation (因为 $landingPageURL 被替换为上面的地图)。

How do I achieve this with condition something like我如何在条件类似的情况下实现这一点

if(map.partialcontainskey(keyname) so, as example, it should conditionally check if $landingPageURL.partialcontainskey($landingPageURL?utm_medium=lp_automation).

how do i achieve this.我如何实现这一目标。 Your help is appreciated.感谢您的帮助。

If your input is following如果您的输入如下

String input = landingPageURL?utm_medium=lp_automation;

You can split the input string and get the required key as follows:您可以拆分输入字符串并获取所需的密钥,如下所示:

String[] urlComponents = input.split("?");
String key = urlComponents[0];
String queryString = urlComponents[1];

And finally you can generate your output as follows:最后,您可以按如下方式生成输出:

String output = map.get(key)+"?"+queryString;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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