Problem Description : - During one discussion I found that programmer stuck at point and I thought I should put on forum.
Today I was searching array conversion into char array. And I checked definition of toCharArray() method of string class.
char str[] = "native".toCharArray();
toCharArray() definition : -
public char[] toCharArray() {
char result[] = new char[count];
getChars(0, count, result, 0);
return result;
}
getChars definition: -
public void getChars(int srcBegin,int srcEnd,char dst[],int dstBegin){
if(srcBegin<0){
throw new StringIndexOutOfBoundsException(srcBegin);
}
if(srcEnd>count){
throw new StringIndexOutOfBoundsException(srcEnd);
}
if(srcBegin>srcEnd){
throw new StringIndexOutOfBoundsException(srcEnd-srcBegin);
}
System.arraycopy(value,offset+srcBegin,dst,dstBegin,srcEnd-srcBegin);
}
Then a native method: -
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);
Here I don't have to understand native but I have to know In such a native method define here in a same way different native method will define for other operating system.