Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help for an Array.

 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
i need help to set data in Array, in this program i set values for names from 1 upto 5 , actually i want that values to be entered by using scanner class then retrieved anytime.

 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check out the Scanner API docs? It has samples of how to use the Scanner class.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Did you check out the Scanner API docs? It has samples of how to use the Scanner class.



Thanks for reply,
i not checked that docs ever but i will check,
One question i think my problem was not about scanner you know.
i have used scanner class i can get input using Scanner with any data type
my question was
how to get input from scanner to set values in Array;
then retrieve them.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the for loop to look for the number? You don't need a number array at all. You can enter a number, calculate the index, and display the name with only one array.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why are you using the for loop to look for the number? You don't need a number array at all. You can enter a number, calculate the index, and display the name with only one array.


Thanks for you reply
i will try to do that.
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muzafar Ali wrote:how to get input from scanner to set values in Array;
then retrieve them.

Use java.util.ArrayList. It's like an array, but it doesn't have a fixed size, so you can add as many Strings to it as you want
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Angstadt wrote:
Muzafar Ali wrote:how to get input from scanner to set values in Array;
then retrieve them.

Use java.util.ArrayList. It's like an array, but it doesn't have a fixed size, so you can add as many Strings to it as you want

Thanks fo reply,
can you post a sample for that?
 
Jon Kho
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


do use "www.google.com" or any other search engines because it has many examples on array list..
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Kho wrote:

do use "www.google.com" or any other search engines because it has many examples on array list..


Thanks for your answer,
i will try to find those by using search engine thanks for help friends.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic