how to call function in Java?

What are good ways to write the array_search (php function) in C and  this function can use in Java(JNI)?

  • Here is the link about php function: array_search http://php.net/manual/en/function.array-search.php use the value to get the array index. I want to try write it in C language and I could use in the java program. the java program is like this: //---------------------------- //array_search java call c public class ArraySearchClient{ public native string   getArrayIndex(String [] stringArray , String key)     static{ System.loadLibrary(){         System.loadLibrary("ArraySearchLibrary");     }     public static void main(String args []){         ArraySearchClient a = new CountIntArrayClient();         String stringList [] = { "tom","cat","jerry","mouse","lion","king"};             //Count the occurrent of the number 2         System.out.println(a.getArrayIndex(stringList, "jerry"));     } } ---------------------------- ---------------------------- ---------------------------- ---------------------------- Hava some quorer could write that in different style, such as -for loop, -while loop, - (maybe could use pointer that i usually confused.. /_\ ) Also, exchange the index between 2 value of array        (or you may say exchange the value between 2 index), eg : array[1] = "Tom"; array[4] = "Tommy"; after exchange, .... array[1] = "Tommy"; array[4] = "Tom"; --------------conclusion------------------- Some brother could tell me some example? programming like the php function array_search in C http://php.net/manual/en/function.array-search.php using -for loop -while loop exchange index and value using pointer (not using temp value) ------------------------the C program may like this ...... //write the C function.   getArrayCount(stringList, key) #include "ArraySearchClient.h" JNIEXPORT jstring JNICALL Java_ArraySearchClient_getArrayIndex (JNIEnv *env, jobject obj, jobjectArray stringArray, jstring key){     jstring *key = null;     jobject *stringArray;     jboolean isCopy;     const char         stringArray = (*env) ->()  .....???     //??????? and then ..???? } ---------------------------- ---------------------------- ---------------------------- ---------------------------- please, great Quora brother..help me..

  • Answer:

    The first hurdle here is that C arrays are nothing like PHP arrays; the latter are a kind of ordered hash table. http://nikic.github.io/2012/03/28/Understanding-PHPs-internal-array-implementation.html If you literally mean a C array, then implementing a value search is a nice beginner's exercise in C.

Toby Thain at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.