Results 1 to 2 of 2
  1. #1
    mainy is offline Member
    Join Date
    Feb 2009
    Posts
    38
    Rep Power
    0

    Default Get value of a String into elements of an Array.

    Hello again.

    I have a String containing information like this:
    Java Code:
    String numbers = "101101";
    How do I place them into an array like this:
    Java Code:
    numberArray[0] = 1;
    numberArray[1] = 0;
    numberArray[2] = 1;
    //... and so on.
    I am trying to work out an automated process to do this. I have a method that needs to convert a string of 1's and 0's into elements of an array. I still can't work out how to do it though, any ideas?

    Thank you

  2. #2
    Hardik is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default

    Here is the code converting string into an array.


    Code:
    String s = "Java";
    char[] char_array = new char[s.length()];

    char_array = s.toCharArray();

    for (int i = 0; i < s.length(); i++){
    System.out.print (char_array[i]);
    }

Similar Threads

  1. Swapping elements of an array help please
    By ikillu in forum New To Java
    Replies: 11
    Last Post: 01-15-2012, 09:49 PM
  2. Splitting single string into array elements
    By phil128 in forum New To Java
    Replies: 11
    Last Post: 01-12-2009, 12:51 PM
  3. Replies: 8
    Last Post: 08-27-2008, 11:45 PM
  4. reference to elements in array
    By Igor in forum New To Java
    Replies: 1
    Last Post: 12-14-2007, 12:56 PM
  5. Help with array of elements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 06:33 PM

Posting Permissions

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