Results 1 to 2 of 2

Thread: Scanner(String)

  1. #1
    ssk2659 is offline Member
    Join Date
    Jan 2015
    Rep Power

    Default Scanner(String)

    Hi! How does the Scanner goes through the String which is passed to it as a parameter. For example, String input = "222 dddd 222 ddd22" is passed to the method and here's the code:

    Java Code:
    public static void sum(String anything)
    Scanner input = new Scanner(anything)
    double nextNumber = inut.nextDouble();
    sum += nextNumber
    So, how does Scanner calculates a passed String? I just want to know the way it calculates/reads. Thanks in advance!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Scanner(String)

    The Scanner is quite clever: the constructor that takes a String as a parameter, wraps the String in a StringReader object (see the API documentation) and it does what it has to do given any Reader object ...

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Can i use Java Scanner with String?
    By guitar-maniac in forum New To Java
    Replies: 7
    Last Post: 09-15-2014, 08:59 AM
  2. scanner to read string or int
    By joecast in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 01:09 AM
  3. Scanner class with a String
    By claudius753 in forum New To Java
    Replies: 5
    Last Post: 03-25-2010, 09:27 AM
  4. String tokenizing with Scanner
    By vijaygk in forum Advanced Java
    Replies: 2
    Last Post: 07-15-2008, 05:44 AM
  5. Replies: 0
    Last Post: 11-20-2007, 05:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts