answersLogoWhite

0

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

12y ago

What else can I help you with?

Related Questions

What are the best features of the free metadata extraction tool available for use?

The best features of the free metadata extraction tool include its ability to extract metadata from various file types, its user-friendly interface, and its customizable options for organizing and exporting metadata.


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.


How the character classified?

Characters can be classified in various ways, such as by their role in the story (protagonist, antagonist, side character), their personality traits (brave, cunning, loyal), or their character arc (static, dynamic, round, flat). These classifications help readers understand the character's function and development within the narrative.


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?


What is the function of magnesium chloride in peroxidase extraction?

Mg2+ is a cofactor of the enzyme peroxidase. In order to keep the enzyme active, this cofactor must be supplied. Magnesium chloride dissociates in solution into magnesium and chloride ions. The cofactor requirement is thus met


What is barium extraction?

Barium extraction refers to the process of separating barium from other elements or compounds it is mixed with. This can involve various techniques such as chemical precipitation, ion exchange, solvent extraction, or electrolysis to isolate barium in its pure form. Barium extraction is commonly done in industries like mining, oil drilling, and chemical production.


What is dramaturgical function?

Dramaturgical function refers to the role or purpose that a character, scene, or element serves within the narrative structure of a play or performance. It encompasses how these components contribute to themes, character development, and the overall storytelling. By analyzing dramaturgical function, one can better understand the dynamics of the plot and the intentions of the playwright. Essentially, it helps to reveal how various elements work together to enhance the audience's experience.


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

first basic function of various is Antenna


What is extraction?

Extraction is the process of separating a desired substance from a mixture using a solvent. This method is often used in chemistry and industry to isolate specific components for further processing or analysis. Extraction can be performed using various techniques such as liquid-liquid extraction, solid-phase extraction, or steam distillation.


What are the various character traits of humans?

nicejoyfulfunnysadmadexciting