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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:12:27+00:00 2026-06-08T03:12:27+00:00

I am new to Java and looking for some help with Java’s Scanner class.

  • 0

I am new to Java and looking for some help with Java’s Scanner class. Below is the problem.
I have a text file with multiple lines and each line having multiple pairs of digit.Such that each pair of digit is represented as ( digit,digit ). For example 3,3 6,4 7,9. All these multiple pairs of digits are seperated from each other by a whitespace. Below is an exampel from the text file.

1 2,3 3,2 4,5

2 1,3 4,2 6,13

3 1,2 4,2 5,5

What i want is that i can retrieve each digit seperately. So that i can create an array of linkedlist out it. Below is what i have acheived so far.

Scanner sc = new Scanner(new File("a.txt"));
    Scanner lineSc;
    String line;
    Integer vertix = 0;
    Integer length = 0;
    sc.useDelimiter("\\n"); // For line feeds

    while (sc.hasNextLine()) {
        line = sc.nextLine();
        lineSc = new Scanner(line);

        lineSc.useDelimiter("\\s"); // For Whitespace
        // What should i do here. How should i scan through considering the whitespace and comma
        }

Thanks

  • 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-08T03:12:29+00:00Added an answer on June 8, 2026 at 3:12 am

    Consider using a regular expression, and data that doesn’t conform to your expectation will be easily identified and dealt with.

    CharSequence inputStr = "2 1,3 4,2 6,13";    
    String patternStr = "(\\d)\\s+(\\d),";    
    // Compile and use regular expression
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(inputStr);
    
    while (matcher.find()) {
        // Get all groups for this match
        for (int i=0; i<=matcher.groupCount(); i++) {
            String groupStr = matcher.group(i);
        }
    }
    

    Group one and group two will correspond to the first and second digit in each pairing, respectively.

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

Sidebar

Related Questions

I'm a java newbie looking for some help reading a file. Here is the
I'm new at Java. I'm looking for some help with homework. I wont post
I need some help writing a class that can go through other java files
Looking at some code, learing about threads : import java.applet.*; import java.awt.*; public class
i am new to java script and i need some help with following code
I am fairly new to Java so am looking for a good way of
We are starting a new Java EE project and am looking for suggestions regarding
I'm learning about text processing in Java for a class and the example in
Doing a small project I have received some Java code that I should rewrite
I'm sure this isn't a hugely complex problem but I'm relatively new to java

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.