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
-2
votes
2 answers

Single element in array

I have been given an exercise involving two arrays. For example: String [] array1 = { "Tv","Iphone","Pc" }; String [] array2 ={"Tv" , "Pc"} (In reality, these arrays may contain some hundred elements coming from files.) I need to find all elements…
Junior Fulcrum
  • 153
  • 1
  • 1
  • 7
-2
votes
2 answers

Out of bounds array exception for one line and not the other?

CODE ArrayList tokens = new ArrayList(); ArrayList PRINT = new ArrayList(); String tok = ""; for(String element : list) { StringTokenizer st = new StringTokenizer(element); …
Mutating Algorithm
  • 2,604
  • 2
  • 29
  • 66
-2
votes
1 answer

null pointer exception with string tokenizer

I have local String array and i try to fill it with the returned tokens from Stringtokenizer.nexttoken when i was declaring the string array as local variable i got i warning Null pointer access: The variable words can only be null at this…
Antwan
  • 3,837
  • 9
  • 41
  • 62
-2
votes
1 answer

String tokenizer.nextToken() return value

When using an if statement, for instance, if((isInt(search1.nextToken()) == true) && search1.nextToken() != "x") would the result returned by search1.nextToken() have different values? This is all wrapped in a while loop as well, and I'm trying to…
Xavier
  • 313
  • 2
  • 5
  • 18
-2
votes
3 answers

Regex and StringTokenizer Syntax Error

I'm new to regular expressions and StringTokenizer, and I'm getting a syntax error whenever I put this regex in matches: while ((line = br.readLine()) != null) { StringTokenizer stringTokenizer = new StringTokenizer(line, "\n"); while…
Pau
  • 55
  • 1
  • 3
  • 7
-2
votes
2 answers

How to count tokens in word which don't duplicate java

I want to count tokens in word which don't duplicate . Example: aabbcc abc Result: 0 3 I must use StrTokazizer or sth like that
MOnasz
  • 99
  • 1
  • 2
  • 8
-2
votes
4 answers

reverse words in a string

I normally could do this, it's very simple code, but I'm having one hell of a brain-fart and I'm eager to figure out my stupidity. I wrote this real quick to try out a new IDE I heard about, and it's supposed to take an inputted string and return it…
user1780932
  • 81
  • 1
  • 7
-2
votes
1 answer

StringTokenizer start from next line if more then one (\t) in file java

I am parsing a file data on the base of \t what I want if found more then one \t start parsing from next new line and start arraylist words from 0. public static void readFile() throws IOException { String line; ArrayList words = new…
Qaiser Mehmood
  • 975
  • 6
  • 21
  • 33
-3
votes
1 answer

Problem in java code

How to add tokens to an arraylist in java? I want to add tokens to an array list. StringTokenizer st = new StringTokenizer(line, ":Mode set - Out of Service In Service"); while(st.hasMoreTokens()){ out.println(st.nextToken());
Ricky
  • 2,323
  • 6
  • 22
  • 22
-3
votes
1 answer

Java: Split text into evenly sized chunks (on white space)

I'm looking if anyone has a good way of splitting a line of text into even sized chunks on white space. Specifically, I'm looking to build a function that takes a string and number of chunks. The goal would be that each line of the split has the…
cdubbs
  • 97
  • 12
-3
votes
3 answers

What is StringTokenizer in Java

I have a problem like this.What does StringTokenizer do than split method for white spaces in java. According to Class StringTokenizer how is it better to use split method instead of using StringTokenizer.
Sajith Herath
  • 1,002
  • 2
  • 11
  • 24
-3
votes
3 answers

trying to print out the array in java

System.out.println("Please input the elements and seperate each by a comma."); e = dk.nextLine(); String[] elems = new String[e.length()]; st = new StringTokenizer(e,","); for (int i = 0; i
7Kei
  • 25
  • 1
-3
votes
1 answer

reading a text file with commas and spaces to calculate GPA

I need to use Buffered Reader and File Reader and format it under columns like this. System.out.println(" Name GPA Classes Hours/Grades" System.out.println(" ------------------ ---- -------- ------------------------…
-3
votes
1 answer

what is meant of "sb.append(new StringBuffer(tx.nextToken()).reverse() +" ")"

What is meant by this line? sb.append(new StringBuffer(tx.nextToken()).reverse() +" ") can anyone explain about it in detail?
-3
votes
3 answers

Finding the total value for elements in a String

My challenge is to find the total value of the elements within a string with user input. Input by user should be as follows: 1,2,3,4,5,6,7... I am running into issues when I tried to use StringTokenizer so I went with the split() method but the…
ml24
  • 1
  • 3
1 2 3
41
42