• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving strings  RSS feed

 
Josef Bartnick
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to take input from the keyboard and save it as a string for future use in the code? If not, is there anything close to performing to what I want?
 
William Barnes
Ranch Hand
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes (of course). Look here
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, you just need to think a bit about the scope of the data, which means when and where you want to use it. For example, here's method scope. I declare a string, get a value and use it all in one method. When I leave the method, it goes "out of scope" and is no longer available.

If I want to use it in another method, I have to make a longer scope. If I store it in a member variable, it lasts as long as the object:

Find a book like Bruce Eckell's Thinking In Java and look up scope in the index. They're likely to have a good discussion.
[ November 05, 2003: Message edited by: Stan James ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!