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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:07:59+00:00 2026-06-18T05:07:59+00:00

I have a file that is set up like: 10 10 12 32 38

  • 0

I have a file that is set up like:

10   10
12   32
38   12

I need to put the lines in the even slots in one array and the lines in the odd slots in another array. I am new to java and I have no idea how to do this. I have been searching the internet for hours and have not found anything. Please help me! I will really appreciate it!

I am using a Buffered Reader to read in the file. I have already written a program that reads in the file and puts all the lines in an array, now I just need to know how to code it to separate the lines. So the lines 1,3,5,7,9 will be in one array and lines 2,4,6,8 will be in another.

Code that I have for putting them in one array:

 private static final String FILE = "file.txt";
    private static Point[] points;


    public static void main(final String[] args){
        try{
            final BufferedReader br = new BufferedReader(new FileReader(new File(FILE)));
            points = new Point[Integer.parseInt(br.readLine())];
            int i = 0;
            int xMax = 0;
            int yMax = 0;
            while(br.ready()){
                final String[] split = br.readLine().split("\t");
                final int x = Integer.parseInt(split[0]);
                final int y = Integer.parseInt(split[1]);
                xMax = Math.max(x, xMax);
                yMax = Math.max(y, yMax);
                points[i++] = new Point(x, y);




            }
  • 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-18T05:08:00+00:00Added an answer on June 18, 2026 at 5:08 am

    try

        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        String line;
        for (int i = 0; (line = br.readLine()) != null; i++) {
            if (i % 2 == 0) {
                list1.add(line);
            } else {
                list2.add(line);
            }
        }
        String[] even = list1.toArray(new String[list1.size()]);
        String[] odd = list2.toArray(new String[list2.size()]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set an array in my config file that I use global in
So, I have a text file that is organized like this <username>:<fullname>:<usergroups> I need
I have a file that I set using PowerShell that contains the version number
I have an image (PNG file) that has an alpha channel that is set
I have a LDIF file that consists of a set of test users and
I have a text file of HTML that includes the following marker set for
I have a UIbutton title that I set with [[buttons objectAtIndex:selectedButtonTag] setTitle:file forState:UIControlStateNormal]; This
I have a method set up that uses jquery form for a file upload
I have a file that looks like: 1 1 C C 1.9873 2.347 3.88776
I have rjecnik.txt file that looks like this mate sime, jure stipica gujo, prvi

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.