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

  • Home
  • SEARCH
  • 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 7820889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:27:58+00:00 2026-06-02T07:27:58+00:00

Below is the text file, in which I want to read each line in

  • 0

Below is the text file, in which I want to read each line in some random way by printing each number in the line in some random order. I can read each line one by one and then print number corresponding to each line in a sequential order, But is there any way we can read line in some random way so that I can print all the numbers in some random order.

 Line1   1  1116    2090    100234  145106  76523
 Line2   1  10107   1008    10187
 Line3   1  10107   10908   1109

Any suggestions will be appreciated. Below is the code that I wrote it will read the line sequentially.

BufferedReader br = null;

    try {
        String sCurrentLine;

        br = new BufferedReader(new FileReader("C:\\testing\\Test.txt"));

        while ((sCurrentLine = br.readLine()) != null) {
            String[] s = sCurrentLine.split("\\s+");
            for (String split : s) {
                if(split.matches("\\d*"))
                System.out.println(split);
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
  • 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-02T07:28:00+00:00Added an answer on June 2, 2026 at 7:28 am

    If you mean to rearrange the order of each line, you can use Collections.shuffle:

    while ((sCurrentLine = br.readLine()) != null) {
        List<String> s = Arrays.asList(sCurrentLine.split("\\s+"));
        Collections.shuffle(s);
        for (String split : s) {
            if (split.matches("\\d*")) {
                System.out.println(split);
            }
        }
    }
    

    This will print the lines sequentially, but the numbers in each line will be shuffled.

    If mean to shuffle the order of the lines as well, just add each line to an ArrayList<List<String>>, shuffle the ArrayList, then shuffle each line:

    ArrayList<List<String>> allLines = new ArrayList<List<String>>();
    while ((sCurrentLine = br.readLine()) != null) {
        allLines.add(Arrays.asList(sCurrentLine.split("\\s+")));
        Collections.shuffle(allLines);
        for (List<String> s : allLines) {
            Collections.shuffle(s);
            for (String split : s) {
                if(split.matches("\\d*"))
                System.out.println(split);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

okay, so i have a text file with example content below line1with some random
I have a file which i will read it line by line. Split each
I have a text file which has first line as below: j0W82LBrSdUbw Basically it
Here I'm trying to read a text file which contains only integers.in every line.For
Below is an excerpt from an .svg file (which is xml): <text xml:space=preserve style=font-size:14.19380379px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu
I know how to create a text file using VBScript which is shown below:
I have an xml file in which i want to read the child nodes
Here I have one file which contains some information, and I want to check
I have a text file which I read using readlines(). I need to start
I've a text file with two rows (say param.txt) which is shown below: Mar2012

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.