6 Replies - 211 Views - Last Post: 12 August 2012 - 09:14 AM Rate Topic: -----

#1 RCharles  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 12-August 12

Texfield to array

Posted 12 August 2012 - 07:00 AM

I have this Textfield populated with numbers that I suppose to sort.
My Question is how can I put the input in the txtfield into an array?

this is a picture of mt txtfield:

Posted Image
Is This A Good Question/Topic? 0
  • +

Replies To: Texfield to array

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Texfield to array

Posted 12 August 2012 - 07:07 AM

You could just use the String.split method on the textbox value, using a space as the delimiter.
Was This Post Helpful? 1
  • +
  • -

#3 RCharles  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 12-August 12

Re: Texfield to array

Posted 12 August 2012 - 07:11 AM

I need to put it on array since I'm gonna perform quicksort. If its ok can post example on how to do it please.
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Texfield to array

Posted 12 August 2012 - 07:36 AM

If you follow the link Atli linked in above post, you will see that that method return an array of strings from the given string and a delimiter.
So in your case, the string is the text from your textfield and according to what character you want to split, you will get your array.
Read that documentation, try something from it and if you have any problems post what you have tried and we will be happy to help..
Was This Post Helpful? 1
  • +
  • -

#5 RCharles  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 12-August 12

Re: Texfield to array

Posted 12 August 2012 - 08:46 AM

im stuck here: im not sure if im doing the correct thing.

    
private void doHeapSort() {
        if(arraydata.getText().equals("")){
            JOptionPane.showMessageDialog (null, "Please insert values to be sorted!" );
        }else
        {
           String inputString = arraydata.getText();
           String[] stringParts = inputString.split(" ");

            }
     }



did it already put in array?
Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Texfield to array

Posted 12 August 2012 - 08:58 AM

Yes it does, why cant you test it and try to print your array and see if it contains anything?
Was This Post Helpful? 0
  • +
  • -

#7 RCharles  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 12-August 12

Re: Texfield to array

Posted 12 August 2012 - 09:14 AM

for(int i=0; i<stringParts.length; i++){
               System.out.println(+i+ stringParts[i]);
           }


output:
01
12
23
34
45
56

Thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1