What is the method to omit a string in java?

Asked By 100 points N/A Posted on -
qa-featured

In Java what is the method to omit a string?

Please help me with this I'm still a fresher for Java.

SHARE
Answered By 5 points N/A #90883

What is the method to omit a string in java?

qa-featured
Hi,  
 
Olivia hope the following steps will guide you in fixing of this issue.
 
  • Using Strings in the Java  the parsing is done by the use of the split () which can be from the String class.
  • StringTokenizer is also the function that can also be used in parsing a string as we mostly don't use it due to some disadvantages present in this StringTokenizer.
  • This may give just in brief overview available in some of the common as well as easiest ways in using the split method.
  • For more on this Strings its better to go through with the Java API documentation for especially split.
  • Example is as follows.
Public class TestStringSplit {
    public static void main(String[] args) throws Exception {
        String s = "1,2,,,,,,3 4 5,,,,,,";
        String[] a = s.split(",");
        System.out.println("Length of array: " + a.length);
        for (int i = 0; i < a.length; i++) {
            System.out.println("Part[" + i + "]: '" + a[i] + "'");
        }
        a = s.split(",", -1);
        System.out.println("n======nLength of array: " + a.length);
        for (int i = 0; i < a.length; i++) {
            System.out.println("Part[" + i + "]: '" + a[i] + "'");
        }
    }
}
 
Output:–>
Length of array: 8
Part[0]: '1'
Part[1]: '2'
Part[2]: ''
Part[3]: ''
Part[4]: ''
Part[5]: ''
Part[6]: ''
Part[7]: '3 4 5'
 
======
Length of array: 14
Part[0]: '1'
Part[1]: '2'
Part[2]: ''
Part[3]: ''
Part[4]: ''
Part[5]: ''
Part[6]: ''
Part[7]: '3 4 5'
Part[8]: ''
Part[9]: ''
Part[10]: ''
Part[11]: ''
Part[12]: ''
Part[13]: ''
 
Thank you..:-)

 

Related Questions