String to Array conversion, help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JavaStudent07
    New Member
    • Jan 2007
    • 64

    #1

    String to Array conversion, help please

    Is it possible to convert a String into an Array? If so could you please guide me on the process of doing so? It would be greatly appreciated.

    Thanks,
    Steve
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Do you mean an array of characters? If so,

    Code:
    String name = "John Doe";
    char[] name2 = new char[name.length()];
    for (int i = 0; i < name.length(); i++) name2[i] = name.charAt(i);

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      an alternative technique is to use method toCharArray() from class String
      Code:
         String s="hello";
         char ch[]= s.toCharArray();

      Comment

      • JavaStudent07
        New Member
        • Jan 2007
        • 64

        #4
        thanks I will see if that info helps at all

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by JavaStudent07
          thanks I will see if that info helps at all
          You can be assured that both methods will work.

          Comment

          Working...