user3326162
user3326162

Reputation: 27

How to test data within a string without using another string

Is it possible to test the data within a string without using another string? For example, if I wanted to test whether String size=("large") is it possible without having to create a second string with the value as large and comparing it using .equals? Is it possible to test case as well (i.e. not using .equalsignorecase)?

Upvotes: 1

Views: 42

Answers (1)

Alan
Alan

Reputation: 822

In a conditional statement you need to compare using the .equals(....) method or .equalsIgnoreCase(...). As far as testing for upper and lower case of characters, take a look at the Character class in the javadocs. I believe you'll find methods like: isLetter() and isUpperCase() and isLowerCase(). Just use a loop to iterate over the string and evaluate over every character.

Upvotes: 1

Related Questions