Results 1 to 4 of 4

Thread: Java; How do I print the *individual* characters of array element/s?

  1. #1
    Join Date
    Nov 2009
    Location
    /dev/
    Beans
    219

    Java; How do I print the *individual* characters of array element/s?

    Hi folks. I am looking to be able to print the individual characters from an array element - if someone would be so kind as to show me how? This is my test piece:

    Code:
    public class Filter{
    	
    	public static void main(String args[]){
    		System.out.println("index\tchar_count\tstring\n");
    		for(int i=0;i<args.length;i++){
    			System.out.println(i+"\t"+args[i].length()+"\t\t"+args[i]);
    		}
    	}
    }
    Thank you

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: Java; How do I print the *individual* characters of array element/s?

    Your array element is a String, yes?

    So you need to print individual characters from a String object?

    Have you looked in the JavaDoc to see if there is anything that could help you?

    java.lang.String

  3. #3
    Join Date
    Aug 2010
    Beans
    12

    Re: Java; How do I print the *individual* characters of array element/s?

    string.toCharArray
    Then loop through your char array
    further information on 'toCharArray' is in the String api as r-senior kindly linked you too.
    Last edited by AshleyT; November 8th, 2010 at 02:22 AM.

  4. #4
    Join Date
    Nov 2009
    Location
    /dev/
    Beans
    219

    Re: Java; How do I print the *individual* characters of array element/s?

    Thanks guys

    Once I get over the teething period I'll be fine. I have grasped the basics now, it's just the obvious things that always throw me; isnt that always the way?
    Last edited by youbuntu; November 9th, 2010 at 05:19 PM.

Bookmarks

Posting Permissions

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