answersLogoWhite

0


Best Answer

JAVA provides a String class that provides the methods to extract the characters out of the given particular string from a String object. Now we shall discuss all the methods provided by JAVA in this blog.

charAt()To extract a particular character from the particular location from the string, charAt()method is used. General form:1char charAt(int where);

Here, where is the index of the character tobe extracted from the string. For choosing the value of where we should keep only one thing in mind that the value should be a nonnegative value. This method returns the character at that particular location.

Example:1public class exam{

2public static void main(String args[]){

3String s="abc";

4char ch;

5ch=s.charAt(2);

6System.out.println("charAt returns: "+ch);

7}

8}

Output of above code is:

getChars()getChars() is used to extract more than one characters at a time. General form:1void getChars(int sourceStart,int sourceEnd,char target[],inttargetStart);

Here,sourceStart specifies the start index of the substring, sourceEnd specifies an index that is one past the end of the desired substring. But the substring contains the characters 1 less than the actual value of sourceEnd. target[] will store the required characters. The index of the target array where the substring is to be stored is specified by the targetStart.

Example:01public class exam1{

02public static void main(String args[]){

03String s="Have a good day every one!!";

04int start=4;

05int end=11;

06char ch[]= new char[end-start];

07s.getChars(start,end,ch,0);

08System.out.println(ch);

09}

10}

Output of above code is:

getBytes()getBytes() stores the characters in an array of bytes, and it uses default character-to-byte conversions. General form:1byte[] getBytes();

It is most useful when you are a String value into an environment that does not support 16-bit Unicode characters.

toCharArray()toCharArray() is used to convert all characters in a String object into a character array. It returns an array of characters for the entire string. General Form:1char[] toCharArray();
User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the various character extraction function available in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

DNA extraction from bacteria?

DNA extraction from bacteria can be achieved in various ways. Yeast is the best resource to extract the DNA bacteria from using extreme rapid extraction method.


Can companies exceed the 140 character limit on twitter?

There are various apps available that allow you to do this. One such app is Twitlonger. However, whatever is after the 140 character mark will have to be accessed by clicking on a link.


Define Chain of Production?

The various stage of production right from extraction of raw materials to the distribution of finished goods to the final consumers The various stage of production right from extraction of raw materials to the distribution of finished goods to the final consumers


Five types of powers available to managers that can be exercised to meet various needs of management function?

Referential Authoritative Coercive Expert Reward


In excel 2013 where are the various function categories stored on the Ribbon?

In Excel Where are the various function categories stored on the Ribbon?


Basic function of various blocks of c band satellite receiving system?

first basic function of various is Antenna


What are the various character traits of humans?

nicejoyfulfunnysadmadexciting


What are the various function of communication?

to build a relationhsip


Definition of functional English?

words perform various function in a sentence.the study of these function is called function english


What are the various techniques that are available to access and use the CAD software?

What are the various techniques that are available to access and use the CAD software?


What Shrek Toys are available online?

Since the movie series Shrek started it has been very popular. Various toys of all of the main characters are available online in different sizes. The most popular is 'Donkey' because he is such a clever yet annoying character.


What Are the Uses of Fume extraction Equipment?

Fume extraction equipment is used in various industries and settings to ensure the safety and health of workers. Some common uses of fume extraction equipment are: Welding Chemical processing Laboratories Automotive industry Pharmaceutical industry, etc. For more details, contact us at +44 (0) 1202 588900