Results 1 to 3 of 3
  1. #1
    kgkamaraj is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default How to convert a string array into object in java

    String[] temp=null;
    String st3=new String(temp);

    I am using this code.. but error message is coming.
    Give solution to recover this error.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    its not really possible to create a string from a null array either.

    if the array was not null then we can create a string by catenating each element together:
    Java Code:
    String[] temp = null;
    // something here would initialize temp[] and set array values right.
    // convert array to a single string
    String st3 = null;
    if (temp != null) {
      StringBuilder b = new StringBuilder();
      for (String s : temp) {
        if (s != null) {
      st3 = b.toString();

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    Please don't post the same question in multiple sub-forums. Stick with a one. I've closed this thread, and please deals with the other thread in New to Java. If you want to clarify anything regarding this, send me a PM.

Similar Threads

  1. How to convert string array into object in java
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 02-12-2010, 12:33 PM
  2. How to convert the Vector object into an array?
    By tyang in forum New To Java
    Replies: 4
    Last Post: 02-08-2010, 08:00 AM
  3. convert a string to an object in java
    By jforce93 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 11:57 PM
  4. Convert Comparable object to string or char
    By ScKaSx in forum New To Java
    Replies: 4
    Last Post: 01-25-2009, 02:02 PM
  5. Convert Linked List Object element to String
    By CirKuT in forum New To Java
    Replies: 2
    Last Post: 12-13-2008, 05:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts