user609300
user609300

Reputation:

Brute-force string manipulation in Java

Any best algorithm or any brute force method to implement the following things?

  1. Find those words are in CAPS.
  2. Count number of words in CAPS.
  3. Count number of words.
  4. Search for exact words.

Cheers,

Venki

Upvotes: 0

Views: 941

Answers (2)

Aba Dov
Aba Dov

Reputation: 962

Use understandable and maintainable code unless you have special need for performance issues for this task

You could try something like this :

the StringTokenizer separates your input line into "words" . you then iterate through them and implement your logic (count, search etc.)

int count =0;

StringTokenizer st = new StringTokenizer(input);
while (st.hasMoreTokens()) {
   addWordsInCapsToList();
   findSpecificWords();
   count ++;
}

Upvotes: 0

maerics
maerics

Reputation: 156434

Regular expressions are a good fit for each of these.

Upvotes: 1

Related Questions