Sort and Object array of Arrays

Hi,
I have an object array that contains a String[] and an int[].
Object[String[], int[]]
The values in the Strings array must be in the same position in the array as those in the int array i.e
String [0] is the string representation of int[0].
Its for a bar chart.
That is all working beautifully.
Now however I want to sort the int array in descending order by the value of the ints in the array and thus the order or the String array has to mirror this.
I am using a comparator to do this but it just wont work. I'm sure this is the way but how should it look?
Has anybody got any ideas?
Thanks in advance,
L.

use the bubblesort:
    for (int i = a.length; --i >= 0; ) {
        for (int j = 0; j < i; j++) {
            if (a[j][1] > a[j+1][1]) {
                int temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
    }

Similar Messages

  • Sorting and return values from parralell arrays

    import java.io.*;
    import java.util.*;
    class Check{
         String words;
         String signature;
         Check(String w, String s){
              words = w;
              signature = s;
    class Test{
         static String[]a = new String[100];
         static String[]b = new String[100];
         public static void main(String[] args)throws IOException{
              Scanner in = new Scanner(new FileReader("input.txt"));
              //Check []ch = new Check[100];
              String str = in.next();
    int z = 0;
          while(!(str.equals("$$$$"))){            
           a[z] = str;
           b[z] = getNumberSequenceFromString(str);
           z++;
           str = in.next();
              insertionSort(a,0,z);
              insertionSort(b,0,z);
         //     for(int i = 0; i < z; i++){
    ///     System.out.println(a);
              for (int i = 0; i < z ; i++){
                   System.out.println(a[i]+" "+b[i]);
              String key = "225533";//should give the word "move", istead it is giving me "TEXT" which is incorrect
              int rope = binarySearch(key,b,0,z-1);
              System.out.println("rrrrrrrrrrrrrrropr "+ rope);
              System.out.println("i found him :"+a[rope/2]);
         }//end main
         public static String getNumberSequenceFromString(String word){
              int l = word.length();
              String str = " ";
              word = word = word.toLowerCase();
         for(int i = 0; i < l; i++){
                   char y = word.charAt(i);
         if(y < 100){
              str +=2;
         }else if(y < 103){
              str +=3;
         }else if( y < 106){
              str +=4;
         }else if( y < 109){
              str += 5;
         }else if(y < 112){
              str += 6;
         }else if(y < 116){
              str += 7;
         }else if (y < 119){
              str += 8;
         }else{
              str +=9;
         }//end for
              return str;
         }//end getWord();
         public static void insertionSort(String[]list,int lo, int n){
         for(int j = lo+1; j < n; j++){
              String key = list[j];
              int k = j-1;
              while(k >= lo && key.compareToIgnoreCase(list[k]) < 0){
                   list[k + 1] = list[k];
                   --k;
              }//end while
              list[k+1] = key;
         }//end for
    }//end insertion sort
         public static int binarySearch(String key, String[]b, int lo, int hi){
         while(lo <= hi-1){
              int mid = (lo + hi)/2;
              System.out.println("i am mmmmmmmmmmmmmid" + mid);
              int cmp = key.compareToIgnoreCase(b[mid]);
              if (cmp==0)return mid;
              if (cmp < 0)hi = mid -1;
              else lo = mid + 1;
         }//end while
         return lo;
    }//end binarysearch
    }//end classAbove is my revise code.  Your idea worked fine, thank you.  I have a problem though.  I tried to create a class eg:
    class Check{
    String words;//for words
    String signature; //for numbers
    Check (String w, String s){
    words = w;
    signature = s;
    The idea was to store the word and its signature as an object, after which I would sort.  Howerver, when I tried reading in the values eg: check[]=str, number, it did not work.  I tried 2 separate arrays, but now I cannot return the correct word. I need some help on this one.
    Questions:
    How could I combine both arrays so that I could sort them, then search a value in the array and return the correct string?
    I tried a class but i could not get it to work.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I'm not going to try to read all that messy code. Here is some advice.
    1. Don't use parallel arrays.
    2. If you're going to insist on doing it the wrong way and using parallel arrays, then first get your sort working for a single array.
    3. If you're going to insist on doing it the wrong way and using parallel arrays, then after getting the sort to work with a single array, in the part where you're swapping elements, whatever you do to swap in the first array, you'll need to do to the second array as well.
    4. Break your code down into methods.

  • How do I put and sort string data into an array?

    I have a txt file that has the following sample data:
    Sample.txt----
    Jones Bill 12,500 Salesperson
    Adams Frank 34,980 Manager
    Adams John 23,000 Salesperson
    Thompson Joe 59,500 Trainee
    I need to incorporate each line of data into an individual array element, while using a user-defined method
    (ex. setAllValues(String last, String first, String salary, String job)
    How do I loop the data into the array to be displayed and what is the best way to do sorts on this sample data. Any code or clues would be super helpful.
    Sanctos

    If you set up an array of Strings you can use the java.util.Arrays.sort() method to sort it. If you need to sort arbitrary Objects (i.e. your 3 strings as a whole entity) your 3-way object will have to either implement Comparable or you could write a Comparitor class to do the ordering. Not much to it, though.
    Dom.

  • Need Help with Array.sort and compare

    Hi
    I have a big problem, i try to make a java class, where i can open a file and add new words, and to sort them in a right order
    Ok everthing works fine, but i get a problem with lower and upper cases.
    So i need a comparator, i tried everything but i just dont understand it.
    How do i use this with Array.sort??
    I hope someone can help me

    Okay, you want to ignore case when sorting.
    There are two possibilities: Truly ignore case, so that any of the following are possible, and which one you'll actually get is undefined, and may vary depending on, say, which order the words are entered in the first place:
    English english German german
    english English german German
    English english german German
    english English German german
    The second possibility is that you do consider case, but it's of lower priority--it's only considered if the letters are the same. This allows only the first two orderings above.
    Either way, you need to write a comparator, and call an Arrays.sort method that takes both array and Comparator.
    The first situation is simpler. Just get an all upper or lower case copy of the strings, and then compare thosepublic int compare(Object o1, Object o2) {
        String s1 = ((String)o1).toUpper();
        String s2 = ((String)o1).toUpper();
        return s1.compareTo(s2);
    } You'll need to add your own null check if you need one.
    For the second way, your comparator will need to iterate over each pair of characters. If the characters are equal, ignoring case, then you compare them based on case. You pick whether upper is greater or less than lower.
    Of course, the need to do this assumes that such a method doesn't alrady exist. I don't know of one, but I haven't looked.

  • Array sort with objects?

    hits = searcher.search(query);
    //java.util.Vector sortHits = new java.util.Vector ();
    int[][] sortHits = new int[hits.length()][1];
    // assign values to array
    int teller = 0;
    for (int i = 0; i < hits.length(); i++)
         Document doc = hits.doc(i);
         String absnumtxt = doc.get("absnumtxt");
         if(sAllCookies.indexOf(absnumtxt) >= 0){
              sortHits[0] = Integer.parseInt(absnumtxt);
              teller++;
              continue;
    But the method Arrays.sort(sortHits); causes a ClassCastException error. Somebody an idea to solve this?
    The structure is:
    sortHits[0][0] = 2
    sortHits[1][0] = 0
    sortHits[2][0] = 0
    sortHits[3][0] = 0
    sortHits[4][0] = 0
    sortHits[5][0] = 0

    A two-dimentional array is an array of array of something.
    Sorting a two-dimentional array requires a Comparator, because you compare uni-dimentional arrays, and arrays are not naturally comparable.
    (BTW, why declaring a two-dimentional array here? you set the second dimention length to 1... a simple array would make it, no?)

  • Can�t open array and object manager

    Hello,
    i�ve done a fresh install of SGD 4 on Fedora Core 3.
    Here I am not able to open array and object manager. I see them running in
    the webtop but get no display.
    I get the following logs:
    in wm_errors: X connection to unix:10.0 broken (explicit kill or server
    shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:12.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    ..skipping...
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:12.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    ~
    and in error.log
    2005/03/01 18:31:54.951 (pid 20049) pem/circuit #0
    Tarantella Secure Global Desktop Enterprise Edition(4.0) ERROR:
    An error occurred reading on circuit fdcircuit. Reason: (9) Bad file
    descriptor.
    The current operation has failed.
    If persistent, restart the server.
    Restarting the server doesn�t help.
    I�ve also set the xscecurity flag to 0.
    This all works fine with Fedora Core 2
    Anyone any Idea?
    Thanks a lot

    Hi Matthias,
    I had similar problems with (local) X apps.
    via ssh, and I mean they arose with tta vers.
    3.42. The problem seems to appear, because
    both tta and ssh (with X forwarding) are
    using a X-display range from :10 upward.
    So, one simply can resolve this by using a different X-display offset for
    ssh, by setting:
    X11DisplayOffset 100
    (for exsample) in sshd_config.
    Then tta still uses displays :10, :11, ...
    but ssh is using :100, :101, ...,
    (assuming that 90 X/RDP emulator-session are enough in this installation!)
    Don't forget to send a SIGHUP to the master
    sshd after changing sshd_config, telling
    'him' to re-read it's config-file.
    One can verify the effect, by calling
    'ssh localhost' and executing: echo $DISPLAY
    this should give something like:
    localhost:100.0
    Kind regards,
    Tankred
    Matthias wrote:
    Hello,
    not all login authorities are disabled. I have only NT auth. enabled. This
    works fine in EE 3.40 on RH 9 and on SGD4.0 on Fedora Core 2. But seems
    not to run on Fedora Core 3.
    Matthias
    Carmelo wrote:
    Mattias,>>
    >
    http://www.tarantella.com/support/documentation/sgd/ee/4.0/help/en-us/base/indepth/disabled_all_login_authorities.html
    Regards,
    Matthias wrote:
    I think I�ve fixed it.
    I just edited ssh_conf and enabled X11forwarding and it works for me.
    But now I have changed the login authority only to NT auth. and I am no
    longer able to log in to tarantella....
    Matthias wrote:
    Hello,
    i�ve done a fresh install of SGD 4 on Fedora Core 3.
    Here I am not able to open array and object manager. I see them running
    in
    the webtop but get no display.
    I get the following logs:
    in wm_errors: X connection to unix:10.0 broken (explicit kill or server
    shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:12.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    ...skipping...
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    X connection to unix:12.0 broken (explicit kill or server shutdown).
    X connection to unix:10.0 broken (explicit kill or server shutdown).
    ~
    and in error.log
    2005/03/01 18:31:54.951 (pid 20049) pem/circuit #0
    Tarantella Secure Global Desktop Enterprise Edition(4.0) ERROR:
    An error occurred reading on circuit fdcircuit. Reason: (9) Bad file
    descriptor.
    The current operation has failed.
    If persistent, restart the server.
    Restarting the server doesn�t help.
    I�ve also set the xscecurity flag to 0.
    This all works fine with Fedora Core 2
    Anyone any Idea?
    Thanks a lot

  • Need to sort an object array using an element in the object.

    hi all,
    i need to sort an object array using an element in the object.can someone throw some light on this.
    Edited by: rageeth on Jun 14, 2008 2:32 AM

    [http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html]

  • ArrayStoreException in WLS 8.1SP3: Object and inner type of array differs

    Has anyone seen this? We seem to get them from time to time, am running WLS 8.1 SP3 on JRockit 1.4.2.03. Stack trace follows.
              cheers
              dim
              <BEA-000802> <ExecuteRequest failed
              java.lang.ArrayStoreException: Object and inner type of array differs.
              java.lang.ArrayStoreException: Object and inner type of array differs
              at weblogic.rjvm.BasicOutboundRequest.sendReceive()Lweblogic.rmi.spi.InboundResponse;(BasicOutboundRequest.java:108)
              at weblogic.rmi.internal.BasicRemoteRef.invoke(Ljava.rmi.Remote;Lweblogic.rmi.extensions.server.RuntimeMethodDescriptor;[Ljava.lang.Object;Ljava.lang.reflect.Method;)Ljava.lang.Object;(BasicRemoteRef.java:137)
              at weblogic.cluster.replication.ReplicationManager_813_WLStub.update(Lweblogic.cluster.replication.ROID;ILjava.io.Serializable;)V(Unknown Source)
              at weblogic.cluster.replication.ReplicationManager.updateSecondary(Lweblogic.cluster.replication.ROID;Ljava.io.Serializable;Ljava.lang.String;)Ljava.lang.Object;(ReplicationManager.java:811)
              at weblogic.servlet.internal.session.ReplicatedSessionData.syncSession()V(ReplicatedSessionData.java:490)
              at weblogic.servlet.internal.session.ReplicatedSessionContext.sync(Ljavax.servlet.http.HttpSession;)V(ReplicatedSessionContext.java:184)
              at weblogic.servlet.internal.ServletRequestImpl.syncSession()V(ServletRequestImpl.java:2471)
              at weblogic.servlet.internal.WebAppServletContext.invokeServlet(Lweblogic.servlet.internal.ServletRequestImpl;Lweblogic.servlet.internal.ServletResponseImpl;)V(WebAppServletContext.java:3679)
              at weblogic.servlet.internal.ServletRequestImpl.execute(Lweblogic.kernel.ExecuteThread;)V(ServletRequestImpl.java:2630)
              at weblogic.kernel.ExecuteThread.execute(Lweblogic.kernel.ExecuteRequest;)V(ExecuteThread.java:219)
              at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:178)
              at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread;)V(Unknown Source)
              Caused by: java.lang.ArrayStoreException: Object and inner type of array differs
              at java.io.ObjectInputStream.readObject(Unknown Source)
              at java.util.HashMap.readObject(Unknown Source)
              at java.io.ObjectInputStream.readSerialData(Unknown Source)
              at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
              at java.io.ObjectInputStream.readObject0(Unknown Source)
              at java.io.ObjectInputStream.readSerialData(Unknown Source)
              at java.io.ObjectInputStream.readObject(Unknown Source)
              at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:120)
              at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:117)
              at weblogic.cluster.replication.ReplicationManager_WLSkel.invoke(Unknown Source)
              at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
              at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
              at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
              at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144)
              at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415)
              at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
              ... 3 more

    You have to be careful how you define your complex elements, define complex elements outside of the root element or in a seperate file and reference them.
              While the following is syntactically correct, in weblogic you will result in the error you had previously
              <element>
              <complex type>
              </complex type>
              </element>
              Instead do
              <element type="ir:ComEx">
              <complex type name="ComEx"></complex type>
              outside of the root element
              Had this exact same problem today, this is how I fixed it

  • Swaping Objects in an Array of Objects

    Hello everyone. I have an Interface Measurable and an Array of Measurable objects. I want to grab 2 random objects from the array and then I compair them. If the compair comes out a certain way I swap the objects and then repaint them on an applet. The problem is when I System.out.println() the array changes I see the swap, but the objects do not swap on the applet when I repaint. I think I its because I'm changing references and not the actual objects, but I can't quite get my head around what I'm doing wrong. Here is the snippet of code from my sort method.
         public void sort()
         //Grab two random int positions from chessPieces[]
              Measurable firstP;
              Measurable secondP;
              int rPos1 = rndn.getRandom(chessPieces.length - 1);
              int rPos2 = rndn.getRandom(chessPieces.length - 1);
              if((chessPieces[rPos1].compareTo(chessPieces[rPos1]) == -1) || (chessPieces[rPos1].compareTo(chessPieces[rPos2]) == 1))
                   System.out.println("BEFORE chessPieces[rPos1] = " + chessPieces[rPos1] + " BEFORE chessPieces[rPos2] = " + chessPieces[rPos2]);
                   firstP = chessPieces[rPos1];
                   secondP = chessPieces[rPos2];
                   chessPieces[rPos1] = secondP;
                   chessPieces[rPos2] = firstP;
                   System.out.println("AFTER chessPieces[rPos1] = " + chessPieces[rPos1] + " AFTER chessPieces[rPos2] = " + chessPieces[rPos2]);
         }

    Here is the painter code. I'm still stuck. I don't know why it doesn't swap.
    public class A1 extends Applet {
    //Instance Variables
    boolean make = true;
    public static Measurable[] chessPieces = new Measurable[50];
    MyRandom rndn = new MyRandom();
         //Constructor
         public A1()
              int delay = 250; //milliseconds
              ActionListener taskPerformer = new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
              repaint();
      new Timer(delay, taskPerformer).start();
         public void paint(Graphics g) {
              Graphics2D g2 = (Graphics2D) g; //Casting
              setBackground(Color.white);
              while(make == true)
                   for(int i = 0; i < chessPieces.length; i++)//Randomly make chess objects
                        int digit = rndn.getRandom(3);
                        if(digit == 0)
                             chessPieces[i] = new King(rndn.getRandom(450), rndn.getRandom(360));
                        else if(digit == 1)
                             chessPieces[i] = new Knight(rndn.getRandom(450), rndn.getRandom(360));
                        else if(digit == 2)
                             chessPieces[i] = new Queen(rndn.getRandom(450), rndn.getRandom(360));
                        else
                             chessPieces[i] = null;
              make = false;
              for(int j = 0; j < chessPieces.length -1; j++)
                   chessPieces[j].getLocation();
                   chessPieces[j].getMeasure();
                   chessPieces[j].draw(g2);
              sort();
         }     // paint

  • Problem with java applet and array of arrays

    hi!
    i'm passing an array of arrays from java applet using
    JSObject.getWindow(applet).call("jsFunction", array(array(), array()) );
    in every other browser than safari 4.0.2 it's no problem to iterate over this array. in safari "array.length" is undefined. is such construction supported in safari's js engine?
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl

    Thanks for the answer but the problem is the type of object of method and how from pl/sql is posiblle to call.
    The method waiting a ArrayofAlicIva, but if i define this object is not posible to set the object inside the array because the wsdl not have this functions.
    I need to define array of objects but the object is inside is the diferent type of array.
    If i Define the array of object correct to object inside, the method expect that the other array type.
    Is a Deadlock ??
    The solution in Java is Simple
    AlicIva[] alicIva = new AlicIva[1];
    alicIva[0]= new AlicIva();
    alicIva[0].setId(Short.parseShort(1));
    fedr[0].setIva(alicIva);
    this is the method imported in java class to form
    -- Method: setIva (LArrayOfAlicIva;)V
    PROCEDURE setIva(
    obj ORA_JAVA.JOBJECT,
    a0 ORA_JAVA.JOBJECT) IS
    BEGIN
    args := JNI.CREATE_ARG_LIST(1);
    JNI.ADD_OBJECT_ARG(args, a0, 'ArrayOfAlicIva');
    JNI.CALL_VOID_METHOD(FALSE, obj, 'FECAEDetRequest', 'setIva', '(LArrayOfAlicIva;)V', args);
    END;

  • How can i convert object to byte array very*100 fast?

    i need to transfer a object by datagram packet in embeded system.
    i make a code fallowing sequence.
    1) convert object to byte array ( i append object attribute to byte[] sequencailly )
    2) send the byte array by datagram packet ( by JNI )
    but, it's not satisfied my requirement.
    it must be finished in 1ms.
    but, converting is spending 2ms.
    network speed is not bottleneck. ( transfer time is 0.3ms and packet size is 4096 bytes )
    Using ObjectOutputStream is very slow, so i'm using this way.
    is there antoher way? or how can i improve?
    Edited by: JongpilKim on May 17, 2009 10:48 PM
    Edited by: JongpilKim on May 17, 2009 10:51 PM
    Edited by: JongpilKim on May 17, 2009 10:53 PM

    thanks a lot for your reply.
    now, i use udp socket for communication, but, i must use hardware pci communication later.
    so, i wrap the communication logic to use jni.
    for convert a object to byte array,
    i used ObjectInputStream before, but it was so slow.
    so, i change the implementation to use byte array directly, like ByteBuffer.
    ex)
    public class ByteArrayHelper {
    private byte[] buf = new byte[1024];
    int idx = 0;
    public void putInt(int val){
    buf[idx++] = (byte)(val & 0xff);
    buf[idx++] = (byte)((val>>8) & 0xff);
    buf[idx++] = (byte)((val>>16) & 0xff);
    buf[idx++] = (byte)((val>>24) & 0xff);
    public void putDouble(double val){ .... }
    public void putFloat(float val){ ... }
    public byte[] toByteArray(){ return this.buf; }
    public class PacketData {
    priavte int a;
    private int b;
    public byte[] getByteArray(){
    ByteArrayHelper helper = new ByteArrayHelper();
    helper.putInt(a);
    helper.putInt(b);
    return helper.toByteArray();
    but, it's not enough.
    is there another way to send a object data?
    in java language, i can't access memory directly.
    in c language, if i use struct, i can send struct data to copy memory by socket and it's very fast.
    Edited by: JongpilKim on May 18, 2009 5:26 PM

  • Querying the data type of objects in an Array?

    I'm able to determine that an argument is an Array using the following query:
    SELECT DATA_TYPE
    FROM all_arguments
    WHERE OBJECT_NAME = 'MY_PROCEDURE' AND ARGUMENT_NAME = 'MY_ARRAY_PARAM'
    DATA_TYPE will be 'PL/SQL TABLE' if the argument/parameter is an array.
    My question is: Is there a way to query what the type of the objects in the array should be? Like NVARCHAR2, VARCHAR2, RAW, DECIMAL, etc.
    Any help is very appreciated!

    I guess the part I'm having trouble with is when the
    Array is defined in a package because the type
    doesn't get listed in "all_coll_types". well, the workaround here would be - the parsing of PACKAGE text - and finding your needed type of array:
    SQL> create or replace package TEST_PACK as
      2          TYPE test_type is table of varchar2(100);
      3   end test_pack;
      4  /
    Package created
    SQL>
    SQL> create or replace package body TEST_PACK as
      2    vc_array test_type;
      3    begin
      4     null;
      5    end;
      6  /
    Package body created
    SQL>
    SQL> select * from user_source t
      2   where name = 'TEST_PACK'
      3  /
    NAME                           TYPE               LINE TEXT
    TEST_PACK                      PACKAGE               1 package TEST_PACK as
    TEST_PACK                      PACKAGE               2         TYPE test_type is table of varchar2(100);
    TEST_PACK                      PACKAGE               3  end test_pack;
    TEST_PACK                      PACKAGE BODY          1 package body TEST_PACK as
    TEST_PACK                      PACKAGE BODY          2   vc_array test_type;
    TEST_PACK                      PACKAGE BODY          3   begin
    TEST_PACK                      PACKAGE BODY          4    null;
    TEST_PACK                      PACKAGE BODY          5   end;
    8 rows selected
    SQL>

  • Objects in an Array

    I'm having trouble getting my objects into an array. The program compilies just fine, but when you run it, it just outputs all null values.
    //import necessary classes
    import java.util.Scanner;
    import java.io.File;
    import java.io.IOException;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import javax.swing.JOptionPane;
    public class DanMPA6
      public DanMPA6() throws IOException
      // get the name of the input file from the username
      String inFile = JOptionPane.showInputDialog( "Enter the name of the file:" ) ; 
      File inputFile = new File(inFile);
      Scanner scan = new Scanner(inputFile);
      scan.useDelimiter("[|\n\r]+");
    // Passenger myPassObj;
      Passenger[] ayPass = new Passenger [1500];
      int count = 0;
      //start the loop
      while (scan.hasNext())
                  // read all of the information from the data file in order
                   int fakeID = Integer.parseInt(scan.next());
                 String fakeClass = scan.next();
                   int fakeSurvive = Integer.parseInt(scan.next());
                 String fakeName = scan.next();
               double fakeAge = Double.parseDouble(scan.next()); 
               String fakeFrom = scan.next();
                   String fakeTo = scan.next();
                   String fakeRoom = scan.next();
                 String fakeTicket = scan.next();
                 String fakeLifeboat = scan.next();     
                 String fakeSex = scan.next();
                 Passenger myPassObj = new Passenger (fakeID, fakeClass, fakeSurvive, fakeName, fakeAge, fakeFrom, fakeTo, fakeRoom, fakeTicket, fakeLifeboat, fakeSex);
                   ayPass[count] = myPassObj;
                   count++;
           /*  String outFile = JOptionPane.showInputDialog (null, "Give the name of the output file:");
               FileWriter fw = new FileWriter (outFile, false);
               BufferedWriter bw = new BufferedWriter(fw);
               bw.write(ayPass[count] + "\n"); */
    public static void main (String [] args) throws IOException
         new DanMPA6();                      
    class Passenger
    // data members
           int passID;
           String passClass;
           int passSurvive;
           String passName;
           double passAge;
           String passFrom;
           String passTo;
           String passRoom;
           String passTicket;
           String passLifeboat;     
           String passSex;
           public Passenger (int fakeID, String fakeClass, int fakeSurvive, String fakeName, double fakeAge, String fakeFrom, String fakeTo, String fakeRoom,  String fakeTicket,  String fakeLifeboat, String fakeSex)
           passID = fakeID;
           passClass = fakeClass;
           passSurvive = fakeSurvive;
           passName = fakeName;
           passAge = fakeAge;
           passFrom = fakeFrom;
           passTo = fakeTo;
           passRoom = fakeRoom;
           passTicket = fakeTicket;
           passLifeboat = fakeLifeboat;     
           passSex = fakeSex;
         

    Thank you very much! That worked. So now I have all my objects in the array, but it seems that I'm running into a different problem when I attempt to output the results into a different .txt file. It creates the file, but with nothing in it! I even tried just a basic line of text and that didn't work either.
    This is the code that I was attempting to do that with:
    FileWriter fw = new FileWriter (outFile, false);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(ayPass[count] + "\n");

  • Converting object wrapper type array into equivalent primary type array

    Hi All!
    My question is how to convert object wrapper type array into equivalent prime type array, e.g. Integer[] -> int[] or Float[] -> float[] etc.
    Is sound like a trivial task however the problem is that I do not know the type I work with. To understand what I mean, please read the following code -
    //Method signature
    Object createArray( Class clazz, String value ) throws Exception;
    //and usage should be as follows:
    Object arr = createArray( Integer.class, "2%%3%%4" );
    //"arr" will be passed as a parameter of a method again via reflection
    public void compute( Object... args ) {
        a = (int[])args[0];
    //or
    Object arr = createArray( Double.class, "2%%3%%4" );
    public void compute( Object... args ) {
        b = (double[])args[0];
    //and the method implementation -
    Object createArray( Class clazz, String value ) throws Exception {
         String[] split = value.split( "%%" );
         //create array, e.g. Integer[] or Double[] etc.
         Object[] o = (Object[])Array.newInstance( clazz, split.length );
         //fill the array with parsed values, on parse error exception will be thrown
         for (int i = 0; i < split.length; i++) {
              Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
              o[i] = meth.invoke( null, new Object[]{ split[i] });
         //here convert Object[] to Object of type int[] or double[] etc...
         /* and return that object*/
         //NB!!! I want to avoid the following code:
         if( o instanceof Integer[] ) {
              int[] ar = new int[o.length];
              for (int i = 0; i < o.length; i++) {
                   ar[i] = (Integer)o;
              return ar;
         } else if( o instanceof Double[] ) {
         //...repeat "else if" for all primary types... :(
         return null;
    Unfortunately I was unable to find any useful method in Java API (I work with 1.5).
    Did I make myself clear? :)
    Thanks in advance,
    Pavel Grigorenko

    I think I've found the answer myself ;-)
    Never thought I could use something like int.class or double.class,
    so the next statement holds int[] q = (int[])Array.newInstance( int.class, 2 );
    and the easy solution is the following -
    Object primeArray = Array.newInstance( token.getPrimeClass(), split.length );
    for (int j = 0; j < split.length; j++) {
         Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
         Object val = meth.invoke( null, new Object[]{ split[j] });
         Array.set( primeArray, j, val );
    }where "token.getPrimeClass()" return appropriate Class, i.e. int.class, float.class etc.

  • I can't seem to create my object for my array!!

    I am in school. My project is to create bank accounts for 3 people. I have 2 for loops, one for my account_numbers and the other for the months of the year. This will track each account's transactions for the year. I initialized my array: int[] accnt_num_array = {123, 523, 723}; Account 123 should be accnt_num_array[0] and so on. My next line is: accnt_num_array = new int[3]; To create the object, and call my method getDeposit, but I get an error: "object type required, but int found." I need help desperately.
    email me at [email protected]
    Any help you could give to a struggling Java programmer would be greatly appreciated.

    int[] accnt_num_array = {123, 523, 723}; Account 123 should
    be accnt_num_array[0] and so on. You have the instantiated the array of ints with the reference named accnt_num_array at this point. You don't need
    accnt_num_array = new int[3]; To create the object,because it's already in existance. Take this out and start using the array.

Maybe you are looking for

  • Itunes (MAc & Windows) shows no remote speakers using AIrport Express

    I have both a Win XP PC and a Powerbook G4 connected to a wireless network using a D-Link DI-624 router. Both computer can connect to the internet, the Powerbook is connected wirelessly. I've set-up my airport express on the wireless network using a

  • Maintenance Optimizer "local logical system is not defined"

    hello, i would like to create a new maintenance transaction to upgrade from SAP ERP 6.0 to SAP ERP 6.0 Enhanced Package 4 i follow the steps in the "maintenance optimizer configuration guide" BUT when i click to create a new maintenance transaction i

  • How to send the invoice through more than one E-mail Ids?

    Hi Experts, I need to send invoice to two email ids. I made a set up in vv31 by setting the transmission medium 7 but it doesn't work. The customer is asking that when i do invoice it should go to two email address. Which output type i should take? K

  • V.15 and New Data Selection

    Hi, in V.15 transaction the "New data selection" is greyed out. How can i allow the user to check/uncheck this box? The problem is when the "New data selection" is checked and when i execute the transaction, the "Name of sold-to party" is empty but w

  • SQL Dev does not recognize NTILE

    I admire how SQL Dev autocompletes GROUP BY statements. However, in a statement like select eaddress, count(*) purchases, NTILE(10) OVER (ORDER BY count(*) asc) AS decile ... etc. it keeps adding the NTILE clause to the GROUP BY statement. NTILE shou