Results 1 to 2 of 2
  1. #1
    Gokul138 is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Post Intaking String and splitting into chars, returning individual chars as string array

    This class intakes a String as its argument and returns an array of string.
    The input string will be splitted in to chars and will be read in to an array as strings....:D

    Java Code:
    /**
     * 
     * @author Gokul
     *
     */
    public class Splitter {
    	private String[] namearray;
    	/**
    	 * 
    	 * default constructor and constructor as mentioned in task
    	*/
    	public Splitter(){}
    	
    
    	/**
    	 * 
    	 * @param name
    	 * @return 
    	 * basically intakes a string and converts each 
    	 * letter to string and stores in an array.
    	 * this constructor returns an array of strings.
    	 */
    	public String[] tokenizeString(String name)
    	{
    		char[] chr = name.toCharArray();
    		namearray = new String[name.length()];
    		for(int k=0;k<name.length();k++)
    		{
    //			converts each letter in the name to string
    			namearray[k]=String.copyValueOf(chr, k, 1);
    		}
    		return namearray;
    	}	
    //	Method to print values in the string array, and this is for testing
    	public void printNameArray()
    	{
    		for(int i =0;i<namearray.length;i++)
    			 {
    				 System.out.println(namearray[i]);
    			 }
    		return;
    	}	
    
    
    }




    //////////////////////////////////////////////////////////////////////////////

    Java Code:
    /**
    *test class for Splitter class
    **/
    
    public class NameSplitter {
    
    	
    	public static void main(String[] args) {
    		 Splitter ns = new Splitter();
    		 ns.tokenizeString("HelloGPS");
    		 ns.printNameArray();		 
    
    	}
    
    }

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    This class intakes a String as its argument and returns an array of string.
    The input string will be splitted in to chars and will be read in to an array as strings....
    Awesome! :D

Similar Threads

  1. create string from array of chars
    By leda in forum New To Java
    Replies: 1
    Last Post: 11-08-2010, 07:39 PM
  2. Make String into chars
    By myst in forum New To Java
    Replies: 19
    Last Post: 06-20-2010, 05:24 PM
  3. Swap chars in a String?
    By spatel14 in forum New To Java
    Replies: 5
    Last Post: 06-08-2010, 10:05 PM
  4. Replacing the chars within a string.
    By Mayur in forum New To Java
    Replies: 2
    Last Post: 03-27-2009, 05:00 AM
  5. How to print chars with symbols from a string
    By blacksky in forum New To Java
    Replies: 23
    Last Post: 01-06-2009, 02:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •