Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.pubnub.api;
  
  import java.util.Vector;

Author(s):
PubnubCore
 
 class PubnubUtilCore {

    
Takes source and delimiter string as inputs and returns splitted string in form of tokens in String array

Parameters:
source , input String
delimiter , delimiter to split on
Returns:
String[] , tokens in and array
 
     public static String[] splitString(String sourceString delimiter) {
 
         int delimiterCount = 0;
         int index = 0;
         String tmpStr = source;
 
         String[] splittedList;
 
         while ((index = tmpStr.indexOf(delimiter)) != -1) {
 
             tmpStr = tmpStr.substring(index + delimiter.length());
             delimiterCount++;
         }
 
         splittedList = new String[delimiterCount + 1];
 
         int counter = 0;
         tmpStr = source;
 
         do {
             int nextIndex = tmpStr.indexOf(delimiterindex + 1);
 
             if (nextIndex != -1) {
                 splittedList[counter++] = tmpStr.substring(
                                               index + delimiter.length(), nextIndex);
                 tmpStr = tmpStr.substring(nextIndex);
 
             } else {
                 splittedList[counter++] = tmpStr.substring(index
                                           + delimiter.length());
                 tmpStr = tmpStr.substring(index + 1);
             }
         } while ((index = tmpStr.indexOf(delimiter)) != -1);
 
         return splittedList;
     }

    
Takes String[] of tokens, and String delimiter as input and returns joined String

Parameters:
sourceArray , input tokens in String array
delimiter , delimiter to join on
Returns:
String , string of tokens joined by delimiter
 
     public static String joinString(String[] sourceArrayString delimiter) {
         StringBuffer sb = new StringBuffer();
 
         for (int i = 0; i < sourceArray.length - 1; i++) {
             sb.append(sourceArray[i]).append(delimiter);
         }
         sb.append(sourceArray[sourceArray.length - 1]);
 
         return sb.toString();
     }

    
Returns string keys in a hashtable as array of string

Parameters:
ht , Hashtable
Returns:
, string array with hash keys string
 
     public static synchronized String[] hashtableKeysToArray(Hashtable ht) {
         Vector v = new Vector();
         String[] sa = null;
         int count = 0;
 
         Enumeration e = ht.keys();
         while (e.hasMoreElements()) {
             String s = (Stringe.nextElement();
            v.addElement(s);
            count++;
        }
        sa = new String[count];
        v.copyInto(sa);
        return sa;
    }

    
Returns string keys in a hashtable as delimited string

Parameters:
ht , Hashtable
delimiter , String
Returns:
, string array with hash keys string
    public static synchronized String hashTableKeysToDelimitedString(
        Hashtable htString delimiter) {
        StringBuffer sb = new StringBuffer();
        boolean first = true;
        Enumeration e = ht.keys();
        while (e.hasMoreElements()) {
            String s = (Stringe.nextElement();
            if (first) {
                sb.append(s);
                first = false;
            } else {
                sb.append(delimiter).append(s);
            }
        }
        return sb.toString();
    }
    static Hashtable hashtableClone(Hashtable ht) {
        if (ht == null)
            return null;
        Hashtable htresp = new Hashtable();
        Enumeration e = ht.keys();
        while (e.hasMoreElements()) {
            Object element = e.nextElement();
            htresp.put(elementht.get(element));
        }
        return htresp;
    }
    static Hashtable hashtableClone(Hashtable ht1Hashtable ht2) {
        if (ht1 == null && ht2 == null)
            return null;
        Hashtable htresp = new Hashtable();
        if (ht1 != null) {
            Enumeration e = ht1.keys();
            while (e.hasMoreElements()) {
                Object element = e.nextElement();
                htresp.put(elementht1.get(element));
            }
        }
        if (ht2 != null) {
            Enumeration e = ht2.keys();
            while (e.hasMoreElements()) {
                Object element = e.nextElement();
                htresp.put(elementht2.get(element));
            }
        }
        return htresp;
    }
    static Hashtable hashtableMerge(Hashtable dstHashtable src) {
        if (dst == null)
            return src;
        if (src == null)
            return dst;
        Enumeration e = src.keys();
        while (e.hasMoreElements()) {
            Object element = e.nextElement();
            dst.put(elementsrc.get(element));
        }
        return dst;
    }
New to GrepCode? Check out our FAQ X