perchance flux dev

fukurou

the supreme coder
ADMIN
Java:
import java.util.HashSet;

public class KeyWords {
    private HashSet<String> hashSet;

    // Constructor to initialize the hashSet
    public KeyWords() {
        this.hashSet = new HashSet<>();
    }

    // Method to add keywords to the hashSet
    public void addKeyword(String keyword) {
        hashSet.add(keyword);
    }

    // Extractor method
    public String Extractor(String str1) {
        for (String keyword : hashSet) {
            if (str1.contains(keyword)) {
                return keyword; // Return the first matching keyword
            }
        }
        return ""; // Return empty string if no keyword matches
    }

    // Main method for testing
    public static void main(String[] args) {
        KeyWords keyWords = new KeyWords();
        keyWords.addKeyword("example");
        keyWords.addKeyword("test");
        keyWords.addKeyword("java");

        String result = keyWords.Extractor("This is a test string for Java programming.");
        System.out.println(result); // Output: test
    }
}
 

fukurou

the supreme coder
ADMIN
Java:
import java.util.HashSet;

public class KeyWords {
    private HashSet<String> hashSet;

    // Constructor to initialize the hashSet
    public KeyWords() {
        this.hashSet = new HashSet<>();
    }

    // Method to add keywords to the hashSet
    public void addKeyword(String keyword) {
        hashSet.add(keyword);
    }

    // Extractor method
    public String Extractor(String str1) {
        for (String keyword : hashSet) {
            if (str1.contains(keyword)) {
                return keyword; // Return the first matching keyword
            }
        }
        return ""; // Return empty string if no keyword matches
    }

    // Excluder method
    public boolean excluder(String str1) {
        for (String keyword : hashSet) {
            if (str1.contains(keyword)) {
                return true; // Return true if a matching keyword is found
            }
        }
        return false; // Return false if no keyword matches
    }

    // Main method for testing
    public static void main(String[] args) {
        KeyWords keyWords = new KeyWords();
        keyWords.addKeyword("example");
        keyWords.addKeyword("test");
        keyWords.addKeyword("java");

        // Testing Extractor
        String extractorResult = keyWords.Extractor("This is a test string for Java programming.");
        System.out.println("Extractor result: " + extractorResult); // Output: test

        // Testing Excluder
        boolean excluderResult = keyWords.excluder("This is a test string for Java programming.");
        System.out.println("Excluder result: " + excluderResult); // Output: true
    }
}
 
Top