Stringtokenizer That Works with Empty Strings

Stringtokenizer That Works with Empty Strings

 import java.util.*;import*;class Class1	{	static Vector split(String string,String delimiter)		{ //StringTokenizer that works with empty strings		boolean wasDelimiter=true;		String token=null;		Vector vector=new Vector();		if(string!=null)			for(StringTokenizer stringTokenizer=new StringTokenizer(string,delimiter,true);stringTokenizer.hasMoreTokens();)				{				if((token=stringTokenizer.nextToken()).equals(delimiter))					{					token=wasDelimiter?"":null;					wasDelimiter=true;					}					else wasDelimiter=false;				if(token!=null)					vector.addElement(token);        			}		return vector;		}	static boolean test(String original,String delimiter)		{ // split, then reconstruct the original string		Vector token=split(original,delimiter);		String reconstructed="";		if(original!=null)			{			for(int i=0;i0)					reconstructed+=delimiter;				reconstructed+=(String)token.elementAt(i);				}    			if(original.endsWith(delimiter)) // allow a trailing delimiter			reconstructed+=delimiter;			}		System.out.println("     original ""+original+""");		System.out.println("reconstructed ""+reconstructed+""");		System.out.println(token.size()+" tokens");		return original==null?true:original.equals(reconstructed);		}	public static void main(String[] argument)		{		BufferedReader in=new BufferedReader(new InputStreamReader(;		for(String string=null;;)			{			System.out.println();			System.out.println("enter string (e.g. a,,b");			try { string=in.readLine(); }			catch(IOException e) { System.out.println(e); System.exit(1); }			if(!test(string,","))				System.err.println("fail!");			if(string==null)				return;			}		}	}
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular