1 / 8

Important Ref. Data Types

Important Ref. Data Types. Tokenizers String customers=“tom,dick,harry”; csv-> String s[]. What is a String Tokenizer?. Class that uses a string to create substrings Substrings are tokens. String input =“this is a sample string”; //– Garbage in

huela
Download Presentation

Important Ref. Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Important Ref. Data Types Tokenizers String customers=“tom,dick,harry”; csv-> String s[]

  2. What is a String Tokenizer? • Class that uses a string to create substrings • Substrings are tokens. • String input =“this is a sample string”; //– Garbage in • String output[] = {“this”, “is”, “a”, “sample”, “string”}; // - Garbage out! • The output is a tokenized version of the input.

  3. Where is StringTokenizer? • in the package java.util. • import java.util.StringTokenizer;

  4. How do you make a StringTokenizer? StringTokenizer st = new StringTokenizer(“1,2,3,4 5\” –6”, “,\” ”);

  5. How do you find out how many tokens there are? • int tn = st.countTokens();

  6. How can I use the StringTokenizer? while (st.hasMoreTokens()) { System.out.println(st.nextToken()); } String s = st.nextToken(); for (int i=0; s != null; s = st.nextToken()) { System.out.println(s); }

  7. How do I read a CSV File? firstName, LastName, StAddress, City, State, ZIP, ph1, ph2, ph3 One record per line. String fn = Futil.getFileName(); File f = new File(fn); FileInputStream fis = new FileInputStream(f); BufferedReader br = new BufferedReader(fis);

  8. How do I read a CSV File?... while ((String s = br.readLine()) != null) { processALine(s); } fis.close();

More Related