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 9244867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:08:11+00:00 2026-06-18T09:08:11+00:00

I read line with BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader.readLine(); Example input is

  • 0

I read line with

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
reader.readLine();

Example input is

1 4 6 32 5

What is the fastest way to read the input and put it into an integer array int[] ?

I’m also looking for some one-line solution if possible.

  • 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-06-18T09:08:12+00:00Added an answer on June 18, 2026 at 9:08 am

    You could use Scanner:

    Scanner scanner = new Scanner(System.in);
    List<Integer> list = new ArrayList<Integer>();
    while (scanner.hasNextInt())
      list.add(scanner.nextInt());
    int[] arr = list.toArray(new int[0]);
    

    Until we have closures in java, this is probably the shortest you can get.

    int[] arr = list.toArray(new int[0]); won’t work because there’s no conversion from Integer to int. You can’t use int as a type argument for generics.

    But yeah If you are working with Java 8 then you can use Stream API for it with the below code snippet(Better way of doing things).

    int[] array = list.stream().mapToInt(i->i).toArray();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CODE: InputStreamReader reader = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(reader); String input =
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
I'm trying to read a line from an io in a non-blocking way. Unfortunately
I'm trying to read input from the terminal. For this, I'm using a BufferedReader.
Hard-to-read-line @daily export sunshine=~/logs/Sunshine-`date '+\%F'` && export sunshineUrl=http://www.sunshine.net/main/search_results.asp?currency_id=1&min_price=&max_price=50000&country_id=241&region_id=&Submit=Search && mkdir -p $sunshine && cd
Say you have a simple loop while read line do printf ${line#*//}\n done <
I want to write a function that read line by line from a socket
I have a file from which i read line by line and i have
I have part of my script that goes like this: while read line do
I'm trying to do something like var=0 grep foo bar | while read line;

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.