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
vote
5 answers

Java How to split arralyist and set in a separate string or array

I am new in Java. I have an object which contains below data 1002,USD,03/09/2019,1004,2,cref,,,,,,,,, 1002,USD,03/09/2019,1005,3,cref,,,,,,,,, 1002,USD,03/09/2019,1003,3,cref,,,,,,,,, I used StringTokenizer to conver this in arraylist List
Muhammad Kazim
  • 611
  • 2
  • 11
  • 26
1
vote
2 answers

String Tokenizer Not Registering String on Second Line as a Token When Reading File Despite Using .nextToken()

I am trying to read a file. The file in question has two strings, one on its own line, like this: COMETQ HVNGAT I am trying to assign each string to its own String variable. However, when I run my code (below), I get a NoSuchElementException for the…
generali
  • 21
  • 2
1
vote
1 answer

I need to extract the first two tokens of a String regardless of how many spaces are in between them

I need to extract only the first two tokens of a String regardless of how many spaces are between them. I then need to store those two extracted tokens in two separate Strings. The code that I have works if there is only one space between the…
shafz047
  • 25
  • 6
1
vote
3 answers

Java - Counting words, lines, and characters from a file

I'm trying to read in words from a file. I need to count the words, lines, and characters in the text file. The word count should only include words (containing only alphabetic letters, no punctuation, spaces, or non-alphabetic characters). The…
1
vote
1 answer

Stringtokenizer undefined

Hi i got some problem making a stringtokenizer method which allow string input by user and count and print tokens. Can someone help me solve error? It says the constructor is undefined. public class StringTokenizer { public static void…
Dave Phan
  • 31
  • 4
1
vote
1 answer

stringtokenizer and an unknown variable type

I’m currently working on a project in which I stream in a text document and tokenize it. The only problem is the types in the text document is unknown, is there any way to check what variable type it is before I set it to a variable in the program?
john smith
  • 11
  • 1
1
vote
3 answers

Method count words in a file

Hi guys I'm writing a method which counts words in a file, but apparently there is a mistake somewhere in the code and the method does not work. Here's my code: public class Main2 { public static void main(String[] args) { …
Bruno
  • 92
  • 1
  • 8
1
vote
0 answers

Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source)

I don't know why it keeps saying this Error in Title My question is "why my StringTokenizer Not working ?" Though it works in the first input "when user input X" , but at "a[i] = Integer.parseInt(st.nextToken());" it doesn't work. The program…
1
vote
2 answers

While loop to create multiple files

I am trying to make a Java application that will take in a bulk file with multiple messages, and then split them up and write each message to its own file. The issue that I am having is that its only creating a file with the last message inside, so…
MR JACKPOT
  • 206
  • 1
  • 3
  • 15
1
vote
2 answers

Extracting numbers from a string in C++

Suppose I have the following char array: char *word="R12_X8_10"; The number of digits are not fixed but the locations with respect to the non-numeric characters are fixed. How can I extract the numbers without boost? I should get {"12", "8", "10"}…
Hassan
  • 157
  • 1
  • 12
1
vote
4 answers

How to make "this, string format" into two tokens ("this" and "string format")

Im reading in a file and each line is as follows Derek Simons, Jason baker Jack Smith, Rob Thomson The problem is with my tokenizer StringTokenizer st = new StringTokenizer(line, ","); while(st.hasMoreTokens()){ …
xiao
  • 1,718
  • 4
  • 23
  • 31
1
vote
2 answers

How to convert char to String in tokenizer in Java

Trying to read a file separated by commas into an array and not sure how to make party into a string to work with tokenizer for(int i = 0; i < s.length; i++) { String str = scan.nextLine(); StringTokenizer st = new…
Avoras
  • 19
  • 4
1
vote
2 answers

how to use StringTokenizer in java for next line?

Let's say I have a continuous String name as temp. The string is divided by new lines, How can I use StringTokenizer on it and get each line separately? String temp = "I am a college kid"; Thank You
user9538414
1
vote
0 answers

Creating a log file in java that outputs certain words from multiple files read

First of all, i am a newbie, i'm doing my best to learn and evolve and i'm taking all of your answers seriously. So esentially, what i have to do is: I'm reading multiple files from multiple folders having a specified encoder (ISO-8859-1) and i…
george b
  • 9
  • 2
1
vote
2 answers

Separate data and store in ArrayList?

I am trying to separate a set of data. I need to store each data into a variable then create an object and put them in an ArrayList. The dataset is in this format lastName, firstName ID num_courses course1_name grade units course2_name grade…
jCheon
  • 13
  • 3