Questions tagged [stringtokenizer]

StringTokenizer is a Java class that breaks a string into tokens.

This tag is used for questions about or involving the StringTokenizer class in Java, which is used to break a single string into multiple, individual "tokens".

StringTokenizer is an old class, called the "legacy class" in documentation, suggesting to use String.split instead. However as of 1.7, it is not deprecated. Another class with similar but more advanced functionality is .

Questions tagged should also be tagged .

Useful links:

627 questions
-1
votes
2 answers

StringTokenizer countTokens() returns 1 with any string

Here is my code: StringTokenizer line = new StringTokenizer("{([]{()})({})}"); System.out.println("Count: " + line.countTokens()); The output is always Count: 1 I know this shouldn't he happening with such a simple code. Could there be something…
CobaltBabyBear
  • 2,188
  • 6
  • 26
  • 47
-1
votes
1 answer

String Tokenizer code not Reading File Correctly

We're learning the uses of a HashMap data structure in class and I've been working on an assignment where we read in a file with 3 columns and a set number of rows. The first column is the full name of a user, the second is their username, and the…
JonMcDev
  • 43
  • 1
  • 7
-1
votes
3 answers

code compiles but i get NoSuchElementException error

This program is suppose to take a people name,sex and number of people have that name and separate name in a String , sex into a char, and number of people with the name into a int. The number of people that have the name is already calculated I…
ttt
  • 39
  • 3
-1
votes
1 answer

NoSuchElementException error

I am trying to see if the next token in a string is equivalent to map key, and adding a message to an array list. ArrayList trace = new ArrayList(); if(!element.startsWith("PRINT")) { while(st.hasMoreTokens()) { …
-1
votes
1 answer

Storing StringTokenizer in an integer array

I'm having a bad time with this error, this code is part of a program that sums the hours and minutes given in two textfields, separated by the symbol ":", the problem is that i can't get the array to store the elements of the StringTokenizer. Here…
Diego RF
  • 11
  • 3
-1
votes
4 answers

how to dynamically allocate size of string array in java

hello I am beginner to work with java. I have following code, where I wanted to initialize the string array word[] dynamically consisting of size of total no. of tokens in all documents [] array. how should I do that? String []result = {"Shipment of…
user2696955
  • 33
  • 2
  • 7
-1
votes
1 answer

Tab as a delimiter(StringTokenizer) not taking as an argument

I have seen several post regarding this.But they tell about split not StringTokenizer. This is my input file:inputfile with tab delimiter I wrote stringTokenizer to get each value in a line.So I am able to get 1.0 3.0 delim1.0 delim3.0 so…
USB
  • 6,019
  • 15
  • 62
  • 93
-1
votes
2 answers

What does StringTokenizer(str," .,?!"); function do?

I was wondering what does the following function do for the following input: String s=" HELLO!THIS IS A TEST.OK?"; StringTokenizer stk=StringTokenizer(s," .,?!"); And also, can anyone explain about this function too? Thanks!
Kartik
  • 53
  • 5
-1
votes
1 answer

Java StreamTokenizer for non-character input?

I have a java binary search tree and I want to create a menu. To this day I used StreamTokenizer to get the user input, But now it doesn't seem to work with "+", "-", "?". My code: public void listen() throws IOException { boolean stay = true; …
Billie
  • 8,938
  • 12
  • 37
  • 67
-1
votes
2 answers

Why is this StringTokenizer not tokenizing properly following the second time?

I want to parse the following using StringTokenizer for every string matching agent>. I tried it using the code like this. Where I am going wrong? StringTokenizer stringtokenizer=new…
user198020
  • 17
  • 2
  • 7
-1
votes
3 answers

Reading small parts of a text file into a text field in GUI

Im going to write a hotel reservation program for my final year at school. I am going to use a text file to have all the guests whose attributes include: Name, Surname, contact details etc. and I want to read these attributes back to the text fields…
-1
votes
1 answer

Java - Reading data using string tokenizer for jTable

I have a file called Items.dat, which looks like this: Item1 subItemA subItemB subItemC Item2 subItemE subItemR subItemT and etc... Using string Tokenizer, how do I input these data into a jTable so Item 1 and Item 2 are headings, and corresponding…
Geuni
  • 93
  • 1
  • 2
  • 12
-1
votes
2 answers

Error with StringTokenizer Iterator Not being found

data_structures/ExpressionEvaluator.java:14: incompatible types.lang.String) found : java.util.StringTokenizer class data_structures.ExpressionEvaluator required: java.util.Iteratoring> st = StringTokenize …
-1
votes
1 answer

Counting number frequency with StringTokenizer

How can I use StringTokenizer to count how many times a number is present in a String if the numbers are separated with "_"? The String has to be entered through the command line. For example if user enters: 1_3_34_12_1_2_34 the output will be 1_2,…
pidev
  • 131
  • 1
  • 1
  • 10
-2
votes
1 answer

extract string using java StringTokenizer, split or scanner

I want to extract the string between and from the following: https://0.0.0.1/abcd/openthis.pdf using StringTokenizer, split or scanner. I'm trying to use StringTokenizer with and as…
user967850
  • 31
  • 6