---
title: "Read Special Character in java Strings"  
description: "Read Special Character in java Strings"  
author: "Anonymous User"  
published: 2015-12-29  
updated: 2015-12-29  
canonical: https://www.mindstick.com/forum/33801/read-special-character-in-java-strings  
category: "java"  
tags: ["java", "string"]  
reading_time: 1 minute  

---

# Read Special Character in java Strings

I want to [test](https://yourviews.mindstick.com/story/1427/explosive-facts-about-trinity-test-world-s-first-nuclear-bomb) wheather my [input string](https://www.mindstick.com/forum/72/input-string-was-not-in-a-correct-format) conatins any special [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) or not. Is there any good [techniques](https://www.mindstick.com/articles/13015/5-practical-tips-and-techniques-to-write-an-essay) for impelmting this?\
I am using charAt() and ASCII [values](https://www.mindstick.com/forum/327/sum-textbox-values)

```
for(int i=0;i<s.length();i++){    char c=s.charAt(i);    if(65<=c<=90)    {        System.out.println("Valid");    }    else if(97<=c<=122)    {        System.out.println("Invalid as it contains lower case letter");        break;    }    else if(48<=c<=57)    {        System.out.println("Invalid as it contains numbers");        break;    }    else        System.out.println("Invalid as it contains special characters");}
```

## Replies

### Reply by Anonymous User

The problem you have is that something like this: 65<=c<=90 will not work in java. You can't chain compares!\
You'll have to write something like this:\

```
if (65 <= c && c <= 90)
```

Or to increase readability i'd suggest you to do something like this:\

```
if ('A' <= c && c <= 'Z')
```


---

Original Source: https://www.mindstick.com/forum/33801/read-special-character-in-java-strings

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
