1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: JAVA classes/constructors question

  1. Apr 1, 2012 #1
    1. The problem statement, all variables and given/known data

    I just have a quick question and hope I can ask it clearly. If I am writing a constructor for a class that takes in one value as an argument, but the value is two words, how can I extract the first and second word?

    For example, if I wrote a class called Name and my constructor looked like this:

    Name(String firstLast)

    And the value sent in was John Smith

    How would I extract John and store it in its own variable? Is this even possible?

    2. Relevant equations

    3. The attempt at a solution
  2. jcsd
  3. Apr 1, 2012 #2

    I like Serena

    User Avatar
    Homework Helper

    Hi csgirl504! :smile:

    The java String class has a method called split() that can do that.
  4. Apr 3, 2012 #3
    I figured it out! Thanks! :)
  5. Apr 3, 2012 #4

    I like Serena

    User Avatar
    Homework Helper

    Good! ;)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook