Results 1 to 5 of 5
  1. #1
    kgkamaraj is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default How to convert 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
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Also posted here.

    A string array instance is an object. So you would convert it by doing nothing.

    The code you posted shows you attempting to create a string from an array of strings. What exactly are you trying to do? Concatenate the string elements? Create a "toString()" form for the array? Something else?

  3. #3
    kgkamaraj is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default Solution

    String arr[]={"s","y"};

    // converting array of string into str object....

    String str=new String(arr.toString());

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    812
    Rep Power
    6

    Default

    I think u are having character array ..not string I think....

    Is this you want.

    class Test
    {
    public static void main(String args[])
    {
    char c [] ={'r','a','m'};

    System.out.println(new String(c));
    }//main

    }//class
    Ramya:cool:

  5. #5
    kgkamaraj is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default Solution

    Hi thank you for your reply....
    I got output for this one.

Similar Threads

  1. 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
  2. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 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
  •