Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

String related issue

$
0
0
i want to compare a String length example String a="1234567" with the elements of String array as in below code.
tell me how to solve this.
In for loop an error message should be print when String (a) length will not match with the String Array elements.

public class Ot {

	public static void main(String arr[])
	{
		
		String a="9727712345678937";                         //16 digit
		String mLength="10,11,12,13,14,15,16,17,18";         
		         // 9
		
		String delimeter=",";
		String[] mLengthArray=mLength.split(delimeter);
		
		
		String msLen=Integer.toString(a.length());             //convert length in string
		
		System.out.println("mLen in string after convert from int(a) is " +msLen);
		
		/*when (String a) is null and (String a) is not equal to mLength means the length of (String a)
                   should  match with the elements stored in mLengthArray[] . if not then print an error 
                    but below code is not working suggest me solution   */
		
		for(int i=0;i<mLengthArray.length;i++)
                 {
                    if(a==null || msLen.equal(mLengthArray[i])  
                     {
                        System.out.println("String a is not equal to mLength or null");
                      }
                 }
                   System.out.println(a);
	}
}




Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>