uyusuk uyusuk - 6 months ago 29
Java Question

How do I get both integer and string from the user

How can I get this when the user enters a mixed input.

We use this for integer:

Scanner input = new Scanner(;
int number = input.nextInt();

We use this for String:

Scanner input = new Scanner(;
String name =;

How can we use both of them at once?
For example: password123
How can i save it?

I think I should use the java generic class.I searched for Java Gneric, but I did not understand.

Thank you.


password123 is a string, that happens to contain numbers.

So using this should work:

Scanner input = new Scanner(;
String name =;