The number of strings containing substrings in the Java lookup string implements code _java

Source: Internet
Author: User

1. Using the IndexOf method:

public class Test11 
{

	private static int counter = 0;
	/**
	 * @param args
	 *
	/public static void main (string[] args) 
	{
		String str = "Sdss**&hgjhadhcasch & ^^ ";
		int i = stringnumbers (str);
		System.out.println (i);
	}
	
	public static int stringnumbers (String str)
	{
		if (str.indexof ("Java") ==-1)
		{return
			0;
		}
		else if (Str.indexof ("Java")!=-1)
		{
			counter++;
			Stringnumbers (Str.substring (Str.indexof ("Java") +4));
			return counter;
		}
		return 0;
	}
} 

2. If the substring is not a string with the same end and end, this can be done:

if (Str.indexof ("Java")!=-1)
	{
		string[] str1 = Str.split ("java");
		System.out.println (str1.length-1);
	}
	else 
	{
		System.out.println (0);
	}

The above Java lookup string contains the number of substrings to achieve the code is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.