Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 732805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:11:02+00:00 2026-05-14T07:11:02+00:00

how to take user input in Array using Java? i.e we are not initializing

  • 0

how to take user input in Array using Java?
i.e we are not initializing it by ourself in our program but the user is going to give its value..
please guide!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:11:03+00:00Added an answer on May 14, 2026 at 7:11 am

    Here’s a simple code that reads strings from stdin, adds them into List<String>, and then uses toArray to convert it to String[] (if you really need to work with arrays).

    import java.util.*;
    
    public class UserInput {
        public static void main(String[] args) {
            List<String> list = new ArrayList<String>();
            Scanner stdin = new Scanner(System.in);
    
            do {
                System.out.println("Current list is " + list);
                System.out.println("Add more? (y/n)");
                if (stdin.next().startsWith("y")) {
                    System.out.println("Enter : ");
                    list.add(stdin.next());
                } else {
                    break;
                }
            } while (true);
            stdin.close();
            System.out.println("List is " + list);
            String[] arr = list.toArray(new String[0]);
            System.out.println("Array is " + Arrays.toString(arr));
        }
    }
    

    See also:

    • Why is it preferred to use Lists instead of Arrays in Java?
    • Fill a array with List data
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a basiceditfield to take input from the user to do some
I have a situation where I have to take input from the user using
i tried to take input from user input type is not determined(can be char
I'd like to take user input (sometimes this will be large paragraphs) and generate
I use an API that expects a SQL string. I take a user input,
I have this simple problem that gets an input from the user using a
My co-worker is challenged with taking user input in Flex and using that data
Suppose i have array of characters. say char x[100] Now, i take input from
In this loop, I'm trying to take user input and continually put it in
I'm working on a web application which will take user input, display it and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.