हम इस ट्यूटोरियल में सीखने वाले है कि जावा करैक्टर क्लॉस (Java Character Class in Hindi) और हम इसे कैसे इस्तमाल कर सकते हैं? आम तौर पर जब हम वर्णों के साथ काम करते हैं, तो हम primitive डेटा प्रकार char का उपयोग करते हैं।
Example
char ch = ‘a’;
// Unicode for uppercase Greek omega character
char uniChar = ‘\u039A’;
// an array of chars
char[] charArray ={ ‘a’, ‘b’, ‘c’, ‘d’, ‘e’ };
हालाँकि विकास में हम ऐसी स्थितियों में आते हैं जहाँ हमें primitive डेटा प्रकारों के बजाय वस्तुओं का उपयोग करने की आवश्यकता होती है। इसे प्राप्त करने के लिए, जावा प्रिमिटिव डेटा टाइप char के लिए रैपर क्लास कैरेक्टर प्रदान करता है।
Table of Contents
चरित्र वर्ग पात्रों में हेरफेर करने के लिए कई उपयोगी वर्ग (यानी, स्थिर) तरीके प्रदान करता है। आप कैरेक्टर कंस्ट्रक्टर के साथ एक कैरेक्टर ऑब्जेक्ट बना सकते हैं –
Character ch = new Character(‘a’);
जावा कंपाइलर कुछ परिस्थितियों में आपके लिए एक कैरेक्टर ऑब्जेक्ट भी बनाएगा। उदाहरण के लिए, यदि आप एक primitive char को एक ऐसी विधि में पास करते हैं जो किसी वस्तु की अपेक्षा करता है, तो संकलक स्वचालित रूप से आपके लिए वर्ण को वर्ण में बदल देता है। यदि रूपांतरण दूसरे तरीके से होता है, तो इस सुविधा को ऑटोबॉक्सिंग या अनबॉक्सिंग कहा जाता है।
Example
// Here following primitive char ‘a’
// is boxed into the Character object ch
Character ch = ‘a’;
// Here primitive ‘x’ is boxed for method test,
// return is unboxed to char ‘c’
char c = test(‘x’);
एस्केप सीक्वेंस (Escape Sequences in Hindi)
बैकस्लैश (\) से पहले एक वर्ण एक एस्केप सीक्वेंस है और कंपाइलर के लिए इसका एक विशेष अर्थ है।
इस ट्यूटोरियल में System.out.println() स्टेटमेंट में स्ट्रिंग प्रिंट होने के बाद अगली लाइन पर आगे बढ़ने के लिए न्यूलाइन कैरेक्टर (\n) का बार-बार उपयोग किया गया है।
निम्न तालिका जावा एस्केप सीक्वेंस दिखाती है –
Escape Sequence | Description |
\t | Inserts a tab in the text at this point. |
\b | Inserts a backspace in the text at this point. |
\n | Inserts a newline in the text at this point. |
\r | Inserts a carriage return in the text at this point. |
\f | Inserts a form feed in the text at this point. |
\’ | Inserts a single quote character in the text at this point. |
\” | Inserts a double quote character in the text at this point. |
\\ | Inserts a backslash character in the text at this point. |
जब एक प्रिंट स्टेटमेंट में एस्केप सीक्वेंस का सामना करना पड़ता है, तो कंपाइलर उसी के अनुसार उसकी व्याख्या करता है।
उदाहरण
यदि आप उद्धरणों के भीतर उद्धरण देना चाहते हैं, तो आपको एस्केप सीक्वेंस का उपयोग करना चाहिए, \”, आंतरिक उद्धरणों पर –
public class Test {
public static void main(String args[]) {
System.out.println(“She said \”Hello!\” to me.”);
}
}
यह निम्नलिखित परिणाम देगा –
Output
She said “Hello!” to me.
करैक्टर मेथड्स (Character Methods in Hindi)
निम्नलिखित महत्वपूर्ण उदाहरण विधियों की सूची है जो कि चरित्र वर्ग के सभी उपवर्गों को लागू करते हैं –
Sr.No. | Method & Description |
1 | isLetter() Determines whether the specified char value is a letter. |
2 | isDigit() Determines whether the specified char value is a digit. |
3 | isWhitespace() Determines whether the specified char value is white space. |
4 | isUpperCase() Determines whether the specified char value is uppercase. |
5 | isLowerCase() Determines whether the specified char value is lowercase. |
6 | toUpperCase() Returns the uppercase form of the specified char value. |
7 | toLowerCase() Returns the lowercase form of the specified char value. |
8 | toString() Returns a String object representing the specified character value that is a one-character string. |
तरीकों की पूरी सूची के लिए, कृपया java.lang.Character API विनिर्देश देखें।
हम उम्मीद करते है कि आपको “जावा करैक्टर क्लॉस (Java Character Class in Hindi)” से सम्बंधित जानकारी हिंदी में समझ में आयी होंगी यदि आपको बताई गई जानकारी अच्छी लगी हो तो अपने दोस्तों में ऐसे शेयर करे जिससे उनकी भी हेल्प हो सके धन्यवाद!