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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:44:09+00:00 2026-05-16T05:44:09+00:00

I encounter some problem when using useDelimiter from the Scanner class. Scanner sc =

  • 0

I encounter some problem when using useDelimiter from the Scanner class.

Scanner sc = new Scanner(System.in).useDelimiter("-");
while(sc.hasNext())
{
    System.out.println(sc.next());
}

if I have this input

A-B-C

the output will be

A B

and wait until I type in another “-” for it to print out the last character

However if I instead of having user input data, and insert a String to the Scanner instead the code will work. What’s the reason for it, and how do I fix it? I don’t want to use StringTokenzier

  • 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-16T05:44:09+00:00Added an answer on May 16, 2026 at 5:44 am

    If the Scanner didn’t wait for you to enter another - then it would erroneously assume that you were done typing input.

    What I mean is, the Scanner must wait for you to enter a - because it has no way to know the length of the next input.

    So, if a user wanted to type A-B-CDE and you stopped to take a sip of coffee at C, it woud not get the correct input. (You expect [ A, B, CDE ] but it would get [ A, B, C ])

    When you pass it in a full String, Scanner knows where the end of the input is, and doesn’t need to wait for another delimiter.

    How I would do it follows:

    Scanner stdin = new Scanner(System.in);
    String input = stdin.nextLine();
    String[] splitInput = input.split("-", -1);
    

    You will now have an array of Strings that contain the data between all of the -s.

    Here is a link to the String.split() documentation for your reading pleasure.

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems you want the item in the link to… May 16, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer You can use a selector on .parent() and .length to… May 16, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer As Tom mentioned, it makes life a lot easier on… May 16, 2026 at 4:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Problem i encounter with outerHTML using IE Browser if i say: txt=Update Complete!; msg
I am using JAXP to generate and parse an XML document from which some
i'm currently experiencing a little problem. I'm using nhibernate with around 40 entities mapped
I am using domain socket to get values from another process, like A to
I encountered this problem when doing some enthusiastic programming. The problem can be expressed
I am using this code to insert some values in MySql table: <?php mysql_connect(localhost,root,root);
One of the things I'm working on right now has some similarities to a
First, the problem: I have several free projects, and as any software they contains
We have a web application that runs on IIS using .NET 2.0 developed and
currently im making some web scraping script. and i was choice PAMIE to use

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.