zoukankan      html  css  js  c++  java
  • Partial Word Searching

    Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings.

    The method takes two parameters, the query string and the array of strings to search, and returns an array.

    If the string isn't contained in any of the strings in the array, the method returns an array containing a single string: "Empty".

    Example: If the string to search for is "me", and the array to search is ["home", "milk", "Mercury", "fish"], the method should return ["home", "Mercury"].

    import java.util.Arrays; class WordSearch { static String[] findWord(String x, String[] y){ final String xLower = x.toLowerCase(); String[] searchResults = Arrays.stream(y) .filter(s -> s.toLowerCase().contains(xLower)) .toArray(size -> new String[size]); return searchResults.length > 0 ? searchResults : new String[] {"Empty"}; } }

    class WordSearch { static String[] findWord(String x, String[] y) { List<String> found = new ArrayList<>(); x = x.toLowerCase(); for(String str : y) { if(str.toLowerCase().indexOf(x) > -1) { found.add(str); } } return found.size() > 0 ? found.toArray(new String[0]) : new String[]{"Empty"}; } }

    class WordSearch { static String[] findWord(String x, String[] y){ ArrayList<String> sols = new ArrayList<String>(); for(int i = 0; i < y.length; i++) { if(y[i].toLowerCase().contains(x.toLowerCase())){ sols.add(y[i]); } } String[] empty = {"Empty"}; return sols.isEmpty() ? empty : sols.toArray(new String[sols.size()]); } }

  • 相关阅读:
    密码朋克的社会实验(一):开灯看暗网
    ThinkPHP5框架缺陷导致远程命令执行(POC整合帖)
    SQL基本注入演示
    从SQL注入到内网漫游
    业务逻辑漏洞探索之敏感信息泄露
    Web安全之XSS Platform搭建及使用实践
    iOS URL Schemes与漏洞的碰撞组合
    phpcms2008远程代码执行漏洞
    使用RSA加密在Python中逆向shell
    源码级调试的XNU内核
  • 原文地址:https://www.cnblogs.com/lgaigai/p/4282583.html
Copyright © 2011-2022 走看看