Pageviews

Sunday 16 June 2013

CharAt() and getChars() in Java

by Unknown  |  in Strings at  Sunday, June 16, 2013

String is the most important part of Java language.The Communication in Java is provided by Strings.String provides a wide range of functions,each having its own task,below are the most commonly used String functions:



1. CharAt(): This function extracts a single character from a string.This method checks the value of the given position which is specified as argument.

Syntax: Stringname.CharAt(Value);

2.getChars():This function can be called as an advanced version of CharAt(),because it displays more than one character you want to display.

Syntax: getChars(int source start,int source end,char target array[],int target start)




For your clarity of the concepts,we had used small programs in which the above functions are covered.


//For charAt() and getChars()

class Sort{
public static void main(String arg[])
{
String k="Koding Point";
char[] ch= new char[10];
System.out.println(k.charAt(7));
k.getChars(2,10,ch,0);
System.out.println(ch);
}

}

The output is:


Strings












0 comments:

Proudly Powered by Blogger.