We have the following string with two separators.String str = "Tom-Hank-s";We want the index of the first occurrence of the separator.For that, you need to get the index of the separator using indexOf()String separator ="-"; int sepPos = str.indexOf(separator);The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "Tom-Hank-s"; String separator ="-"; System.out.println("String: "+str); int sepPos = str.indexOf(separator); System.out.println("Separator's first occurrence: "+sepPos); } }OutputString: Tom-Hank-s Separator's first occurrence: 3
We have the following string with a separator.String str = "David-Warner";We want the substring before the last occurrence of a separator. Use the lastIndexOf() method.For that, you need to get the index of the separator using indexOf()String separator ="-"; int sepPos = str.lastIndexOf(separator); System.out.println("Substring before last separator = "+str.substring(0, sepPos));The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "David-Warner"; String separator ="-"; int sepPos = str.lastIndexOf(separator); if (sepPos == -1) { System.out.println(""); ... Read More
This example demonstrate about How to draw close shape in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken imageview and added background as background.xml.Step 3 − Add the following code to drawable/ background.xml Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of ... Read More
Let’s say we have the following string.String str = "Learning never ends! Learning never stops!";In the above string, we need to find out how many times the substring “Learning” appears.For this, loop until the index is not equal to 1 and calculate.while ((index = str.indexOf(subString, index)) != -1) { subStrCount++; index = index + subString.length(); }The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "Learning never ends! Learning never stops!"; System.out.println("String: "+str); int subStrCount = 0; String subString ... Read More
This example demonstrate about How to create circler edit text in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken edit text and added background as background.xml.Step 3 − Add the following code to drawable/ background.xml Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the ... Read More
This example demonstrate about how can I add an image on EditText.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken edit text and added background as background.xml.Step 3 − Add the following code to drawable/ background.xml Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the ... Read More
The following are our strings with single and double quote.String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!";Above, for single quote, we have to mention it normally like.This is Jack's mobileHowever, for double quotes, use the following and add a slash in the beginning as well as at the end.String str2 = "\"This is it\"!";The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!"; System.out.println("Displaying Single Quote: "+str1); ... Read More
A number can be multiplied by 2 using bitwise operators. This is done by using the left shift operator and shifting the bits left by 1. This results in double the previous number.A program that demonstrates multiplication of a number by 2 using bitwise operators is given as follows.Example Live Demousing System; namespace BitwiseDemo { class Example { static void Main(string[] args) { int num = 25, result; result = num
Let’s say the following is our string.String str = "Java is a programming language. James Gosling developed it.";We will now see how to split a string using the split() method. Include the delimiter as the parameter.String[] strSplit = str.split("\.");Above, we have split the string with dot as you can see under the split methods parameter.The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "Java is a programming language. James Gosling developed it."; System.out.println("String: "+str); String[] strSplit = str.split("\."); ... Read More
Organized and unorganized sectors are mainly differentiated based on employment conditions.Organized Sector − It is incorporated with the appropriate authority and follows the rules and regulations. It is mostly related to Government or some large-scale operations. As these organizations strictly follow government rules they adhere to acts like Factories Act, Bonus Act, PF Act, Minimum Wages Act etc. Workers are paid remuneration as monthly salary regularly and there will be job security.Unorganized Sector − The unorganized sector is the one which is not incorporated into the government. Small-scale operations, petty trade, private business, domestic workers and construction workers etc. come ... Read More