Problem in converting vector to array of strings

hi
i am having a vector which in turn contains hashtable as elements
Vector v=new Vector()
Hashtable ht=new Hashtable();
v.add(ht.add("key1",value1))
v.add(ht.add("key2",value2))
v.add(ht.add("key3",value3))
v.add(ht.add("key4",value4))now i am trying to conver this vector in to a array of string like
String[] str=(String[])v.toArray(new String[v.size()]);but i am getting java.lang.ArrayStoreExceptioncan anybody help me plz
Thanks

Hi,
The api for public Object[] toArray(Object[] a) says
Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.
ArrayStoreException will be thrown if the runtime type of a is not a supertype of the runtime type of every element in this Vector.
The runtime type of the elements of the vector is Hashtable.
Because String is not a supertype of Hashtable the ArrayStoreException is thrown.

Similar Messages

  • How to convert an int array to string array?

    Hi,
    Can anyone please help me with this question?
    int number={4,6,45,3,2,77};
    I like to convert this into a list and sort
    List mylist = Arrays.asList(number);
    Collections.sort(mylist);
    But first I need to convert the int array to String array.
    Please advise. Thanks.

    If you want to convert your int array to a String array, you have no choice but doing a conversion element by element in a for loop.
    However, if the sort method doesn't behave as desired, you can use the one with 2 parameters, the second parameter being a comparator class.
    Check the javadoc for more information : http://java.sun.com/j2se/1.3/docs/api/java/util/Collections.html
    /Stephane

  • How to return array of String to a java program.! ??

    Hi All,
    I am new to JNI programming. so trying with simple example. I am having one problem. I have one array of String in my Java program. I want to reverse all the elements in this array and want back this new array in the same form i.e. array of string. So how can I do this ??
    Please guide me.....
    The function of defination of array in my java code is
    public native String[] getReverseStringArray(String[] arrString);
    where as my array is like:
    String[] arrStr = {"one", "two", "three", "four", "��������","�c��","�J�^�J�i"};
    and I am calling function in C file like:
    arrStr = employee.getReverseStringArray(arrStr);
    and the function defination in my c file is
    JNIEXPORT jobjectArray JNICALL
    Java_Emp_getReverseStringArray (JNIEnv *env, jobject obj, jobjectArray arr)
    // some code will come here......
    So can anybody tell me how to do this ??
    Thanx in advance...
    Pandurang
    [email protected]

    Hi,
    this is quite simple. Here an example function that works like this:
    JNIEXPORT jobjectArray JNICALL Java_cadagent_ugopen_UgAssembly_jni_1getStructure
    (JNIEnv *env, jclass cls, jstring part)
    jobjectArray retvals = NULL;
    jstring j_val = NULL;
    int child_count = 5;
    /* initialize return array */
    j_val = (*env)->NewStringUTF(env, "");
    retvals = (*env)->NewObjectArray(env, child_count, (*env)->FindClass(env, "java/lang/String"), j_val);
    for (i=0;i<child_count;i++)
    j_val = (*env)->NewStringUTF(env, "some text");
    (*env)->SetObjectArrayElement(env, retvals,i, j_val);
    return retvals;
    Hope this answers you question.

  • Converting Array of string to an array of integers

    I have a problem converting a array of string to array of int's
    This is my code...
    String[] forminfo = request.getParameterValues("forsendur");
          int[] forminfoInt = Integer.parseInt(forminfo); This is the error message:
    Incompatible type for method. Can't convert java.lang.String[] to java.lang.String.
                          int[] forminfoInt = Integer.parseInt(forminfo);
                                                               ^can anyone help me with this?

    ParesIn methos returns a int buto not a int[]. You must iterate along the String array and perform the methos for each element setting the return value into the element of the int array
    Ej:
    int[] intArray = new int[stringArray.length]
    for(int i = 0; i < stringArray.length; i++)
    intArray[i] = Integer.parseInt(stringArray);

  • Strange problem in converting between XML to string and vice versa

    i have an application that needs to send an XML document
    over the wire. For this reason, I need to convert the
    doc into a String at the sending side and back to Doc
    at the receiving side. This document is stored in a "CLOB"
    column in a table in the database. I use XDK to retrieve
    this entire row (including the CLOB - hence this is an XML
    document which has a column that itself is an xml document in
    string format - this is just the clob read in by XDK).
    Thus the row looks like
    <ROWSET>
    <ROW>
    <col1> A <col1>
    <CLOB_COL> ..clob value of an xml doc..</CLOB_COL>
    </ROW>
    </ROWSET>
    When I convert this document into String and back, one of the "<"
    tags in the clob column document gets changed to "&lt;" and hence
    the parsing fails! I have used the latest label of the XDK build
    to get the latest parser jar but still i have the same problem.
    I am using the following routines for the conversion.
    /* for converting document to string */
    public static String convertToString(XMLDocument xml) throws
    IOException
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    xml.print(pw);
    String result = sw.toString();
    return result;
    /* for converting string to document */
    public static XMLDocument convertToXml(String xmlStr)
    throws
    IOException,SAXException
    ByteArrayInputStream inStream = new
    ByteArrayInputStream(xmlStr.getBytes());
    DOMParser parser = new DOMParser();
    parser.setPreserveWhitespace(false);
    parser.parse(inStream);
    return parser.getDocument();

    How do you get the XML document? Do you use XSU? You can use:
    String str = qry.getXMLString();
    to get the result XML document in String.
    XSU will escape all of the < and >. Or the the XML document in
    one of the column will make the result XML doc not well-formed.
    Not quite understand your problem. You can send me your test
    case.
    i have an application that needs to send an XML document
    over the wire. For this reason, I need to convert the
    doc into a String at the sending side and back to Doc
    at the receiving side. This document is stored in a "CLOB"
    column in a table in the database. I use XDK to retrieve
    this entire row (including the CLOB - hence this is an XML
    document which has a column that itself is an xml document in
    string format - this is just the clob read in by XDK).
    Thus the row looks like
    <ROWSET>
    <ROW>
    <col1> A <col1>
    <CLOB_COL> ..clob value of an xml doc..</CLOB_COL>
    </ROW>
    </ROWSET>
    When I convert this document into String and back, one of the "<"
    tags in the clob column document gets changed to "<" and hence
    the parsing fails! I have used the latest label of the XDK build
    to get the latest parser jar but still i have the same problem.
    I am using the following routines for the conversion.
    /* for converting document to string */
    public static String convertToString(XMLDocument xml) throws
    IOException
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    xml.print(pw);
    String result = sw.toString();
    return result;
    /* for converting string to document */
    public static XMLDocument convertToXml(String xmlStr)
    throws
    IOException,SAXException
    ByteArrayInputStream inStream = new
    ByteArrayInputStream(xmlStr.getBytes());
    DOMParser parser = new DOMParser();
    parser.setPreserveWhitespace(false);
    parser.parse(inStream);
    return parser.getDocument();

  • Array of strings to vector

    Hi,
    I have an array of strings like:
    private String myStrArr[];
    myStrArr = new String[256];
    I have to get rid of hard coded size.
    Is it ok to use vector instead , or is there another way to get rid of hard coded size.
    If we can use vector instead , is there a solution similar for booleans??
    I also have an array of booleans:
    private boolean myBoolArr[];
    myBoolArr = new boolean[256]

    You can wrap the primitive booleans you have in the Boolean class via
    myList.add(new Boolean(primitiveBooleanValue));Even better, to save space, use the already existing Boolean values instead of creating new ones. If you are using Java 1.4, you can:
    myList.add(Boolean.valueOf(primitiveBooleanValue));Otherwise you can do one of these:
    myList.add( primitiveBooleanValue ? Boolean.TRUE : Boolean.FALSE );

  • Problem in setting vector or string[] as the "value object" in hashmap

    Hey I am new to this forum.
    I am doing a project in which i need to store a array of strings as "value object" for a unique key in hashmap.
    as I populate the hashmap from external file according to key and setting the string[]. The hashmap is taking the value field same for each entry i.e the last field as i keep updating the same variable and then putting it into hashmap.
    Please give solution to my problem???
    if question not clear,please tell me- i will add more information
    Edited by: AnkitNahar on Apr 4, 2009 8:06 AM

    I tried using the method suggested by you...but it is of same case as using the string[].
    I need to loop the statements in which the hashmap is populating so cant change the variable names in the dd.put() statements. When the below code executes it shows the same set of string for both the keys, that was the problem i was facing with string[].
    here is the example with two entries....same thing in looping.
    HashMap<String,Set<String>> dd=new HashMap<String,Set<String>>();
    String word = "Hello";
    Set<String> alternativeWords = new HashSet<String>();
    alternativeWords.add("Hi");
    alternativeWords.add("Yo");
    dd.put(word, alternativeWords);
    alternativeWords.clear();
    alternativeWords.add("hey");
    word="yep";
    dd.put(word,alternativeWords);
    System.out.println(dd.get("Hello").toString());
    System.out.println(dd.get("yep").toString());

  • WHY WE USE VECTOR NOT ARRAY STRING

    Hi
    I want to know why we use Vector not bufferstring.
    What is the difference Vector(1,1) and STRING[1][1]?
    Which one we will prefer?
    Why we will prefer one of them?
    Please help me to find out.

    There are huge differences between array and Vector.
    Array is a special class that allows to keep references to a number of Objects of some type. It has a maximum length set during construction, and does not offer any methods to change it's size (without defining a new array).
    Vector is a class (thread-safe unlike it's new version ArrayList) that allows to keep references to any Object (may be of different types). It doesn't have a maximum length set, and can be potentionally of any size. It allows to easily remove, add, insert new elements and keeps all the elements in the order they were added (unless some object was inserted). This is a really well written class, and I'm always using it for storing some objects.
    Hope it was helpful.

  • Convert an array of strings into a single string

    Hi
    I am having trouble trying to figure out how to convert an array of strings into a single string.
    I am taking serial data via serial read in a loop to improve data transfer.  This means I am taking the data in chunks and these chunks are being dumped into an array.  However I want to combine all elements in the array into a single string (should be easy but I can't seem to make it work).
    In addition to this I would also like to then split the string by the comma separator so if any advice could be given on this it would be much appreciated.
    Many Thanks
    Ashley.

    Well, you don't even need to create the intermediary string array, right? This does exactly the same as CCs attachment:
    Back to your serial code:
    Why don't you built the array at the loop boundary? Same result.
    You could even built the string directly as shown here.
    Message Edited by altenbach on 12-20-2005 09:39 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    autoindexing.png ‏5 KB
    concatenate.png ‏5 KB
    StringToU32Array.png ‏3 KB

  • How to convert 1D array of string to string

    How to convert 1D array of string to string.

    Maximus00, as Pavel indicated, there is a lesser known feature of "Concatenate Strings" that does exactly what your code is doing if the input is an array of strings. In one step! See attached image.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ConcatenateArray ofStrings.gif ‏7 KB

  • Converting array of strings using SCMS_STRING_TO_XSTRING

    Hello all,
    FM SCMS_STRING_TO_XSTRING can be used to convert a String to a XSTRING and then we can use FM SMUM_XML_PARSE to parse the XML.
    Now I will have a array of strings as an output from a web service and I need to parse them .. so the Function modules mentioned above are used for a single string but how to convert the array of strings??
    Please suggest me on how to proceed.
    Thanks in advance,
    Regards,
    Suman.

    Hi Raja,
    Thanks for your suggestion.
    I have yet to try this..I will update with the results.
    Regards,
    Suman.

  • Problem returning array of strings

    Hi,
    I am trying to return an array of strings from C to Java.The function I am using is
    char rec[20][20];
    int num=0;
    /* incrementing num and copying into the array everytime a record is added*/
    JNIEXPORT jobjectArray JNICALL Java_jnimidlet_list_1rec
    (JNIEnv *env, jobject obj)
    jstring str;
    jobjectArray args = 0;
    jsize len = num;
    int i=0;
    args = (*env)->NewObjectArray(env, len,
    (*env)->FindClass(env, "java/lang/String"), 0);
    for( i=0; i < len; i++ )
    str = (*env)->NewStringUTF( env, rec);
    (*env)->SetObjectArrayElement(env, args, i, str);
    return args;
    In the java code:
    String []all=list_rec();
    when this function is called I get the error:
    Unhandled exception
    Type=GPF vmState=0xffffffff
    ExceptionCode=0xc0000005 ExceptionAddress=0x00000000 ContextFlags=0x0001003f
    Handler1=0x10f01530 Handler2=0x10026280
    Module=C:\wsdd5.5\wsdd5.0\ive\bin\j9.exe
    Module_base_address=0x00000000
    Offset_in_DLL=0x00000000
    EDI=0x0012fc14 ESI=0x10f01530 EAX=0x00020020
    EBX=0x00148e34 ECX=0x0017469c EDX=0x00020020
    EBP=0x00149d40 ESP=0x0012fbec EIP=0x00000000
    Thread: main (priority 5) (LOCATION OF ERROR)
    Thread: Gc Thread (priority 5) (daemon)
    Can anyone pls tell me how do I come out of this problem.
    Please help.
    Thanx in advance,
    pri_rav

    Hi Priya,
    I dont see any problem. I tried to work with your code it works fine without any exception. Please make sure all ur rec char buff contents are null terminated and your 'i' counter is initialized properly and stops properly. According to me there shouldn't be any problem with JVM. I hope you are aware of c programming,which doesn't check for array boundaries. You may accidentally go out of array size allocated. So my suggession is to check you rec buff going above any of the dimension. Put a watch on 'i' variable content as well. Try and let me know whether it solves your problem. If it doesn't reply me with more details. I will try helping you.
    Thanks,
    Regards,
    Ravikiran.

  • How do i convert a double array (with spaces and tabs) to a string?

    Hi
    In our files, we have a mixture of spaces and tabs as a delimeter. How do I convert a double array into a string?
    Thank you.

    Not sure about the last part of your question.
    The Search and Replace pattern can be better than the simple Search and Replace string when you have to do complex searchs, such as detecting multiple spaces.
    Have a look at the attachment.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    ReplaceSpaces.vi ‏27 KB

  • What is the best way to convert a cluster into byte array or string

    I'm writing a program that sends UDP packets and I've defined the data I want to send via large clusters (with u8/u16/u32 numbers, u8/u16/u32 arrays, and nested clusters). Right before sending the data, I need to convert the clusters either into strings or byte arrays. The flatten to string function is almost perfect for this purpose. However, it's appending lengths to arrays and strings which renders this method useless, as far as I can tell. 
    As I have many of these clusters, I would rather not hard code the unbundle by names and converting/typecasting to byte arrays or strings for each one. 
    Is there a feature or tool I am overlooking? 
    Thank you! 

    deceased wrote:
    Flatten to string has a boolean input of "Prepend string or array size" ... The default value is true.
    That only specifies if a string or array size should be prepended if the outermost data element is a string or array. For embedded strings or arrays it has no influence. This is needed for the Unflatten to be able to reconstruct the size of the embedded strings and arrays.
    The choice to represent the "Strings" (and Arrays) in the external protocol to LabVIEW strings (and arrays) is actually a pretty bad one unless there is some other element in the cluster that does define the length of the string. An external protocol always needs some means to determine how long the embedded string or array would be in order to decode the subsequent elements that follow correctly.
    Possible choices here are therefore:
    1) some explicit length in the protocol (usually prepended to the actual string or array)
    2) a terminating NULL character for strings, (not very friendly for reliable protocol parsing)
    3) A fixed size array or string
    For number 1) and 2) you would always need to do some special processing unless the protocol happens to use explicitedly 32 bit integer length indicators directly prepended before the variable sized that.
    For number 3) the best representation in LabVIEW is actually a cluster with as many elements inside as the fixed size.
     

  • Would like some help converting an array of strings into multiple parsed string arrays

    Hello everyone.
    this is a very novice question and I sincerely apologize for that, but i need some direction!
    i have an array of strings:
    (('J01',), ('0', '0', '0', '1'))
    (('J02',), ('0', '1', '0', '1'))
    (('J03',), ('0', '0', '0', '0'))
    ect...
    i would like to know what are some of the best ways to gain access to this information (aka, parse it). The field lengths are not static and all those ones and zeros could very possibly be two digits at times (0 = off state, 1-100 = on state), so simply pulling characters out of a given position of the string will not always work.
    what i would like to achieve is to make either separate arrays for each desirable element, eg:
    array one:
    J01
    J02
    J03
    array two:
    0
    0
    0
    array three:
    0
    1
    0
    and so on.
    or maybe even a matrix (if that’s feasible).
    other than that I am totally up for suggestions!!
    thank you very much,
    Grant.

    Assuming fixed structure (not necessarily length of the different numbers or names).

Maybe you are looking for

  • Error Message when saving a scan with Officeject Pro L7555

    When the drive for the printer goes to save a scanned picture or document to Word2007 I get the message:  An error occured saving the images to the chosen file location.  The extended error information is:  8,[(6,1015,-2147220489)].  Printer scans th

  • Installed iweb as part of ilife06, application iWeb quit unexpectedly

    Hi all, I hope you can throw some helpful advice at me! I have just purchased iLife06 to use iWeb, installed it, patched it, and launched it. 10 seconds in I get a application iWeb quit unexpectedly box, the report box contains this load of geektalk:

  • F-28 cash discount error

    For making payment to the billing document from SD in f-28 t-code, we are getting the cash discount percentage but the cash discount amount is not displying even we specified the payment terms in Sales order creation. Even, if we specify manually the

  • Error in the proc which has dynamic query in it.

    I have a proc as below create or replace procedure dynamic_Sql (id in number, obj_id in number, id2); is xxxx varchar2(30); sql_stmt1 VARCHAR2(10000); cusor c is select distinct dep from department where dept_id = 10; Beign select table_name into xxx

  • PC Sync 2 Synchronisation Extension in Firefox 3.5...

    Does anyone from Nokia have an estimated release date for a new version of the bookmark synchronisation extension between PC Sync 2 and Firefox 3.5.2? It's been quite a long time since Firefox 3.5 came out, and those of us who've upgraded have been c