Posted By

MarcDexet on 06/26/07


Tagged

String null tokenizer


Versions (?)

NullTokenizer


 / Published in: Java
 

A tokenizer that takes missing values between two delimitators as a null value.

  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class NullTokenizer {
  5.  
  6. public static List asList(String str, String delim) {
  7. List data = new ArrayList();
  8. java.util.StringTokenizer st = new java.util.StringTokenizer(str, delim , true);
  9. while (st.hasMoreTokens()) {
  10. String s = st.nextToken();
  11. if (s.equals(delim)) {
  12. data .add( null );
  13. } else {
  14. data.add( s );
  15. if (st.hasMoreTokens())
  16. st.nextToken();
  17. }
  18. }
  19. return data;
  20. }
  21. }

Report this snippet  

You need to login to post a comment.