- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2617 Articles for Java
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
107 Views
The String class of the java.lang package represents set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. A string index is an integer representing the position of each character in the string starting from zero.A substring is a part/segment of a string. You can identify a substring of a string using the substring() method of the String class. This method have two variants −substring(int beginIndex)This method accepts an integer value representing an index in the current string and returns the substring starting from the given index to the end of ... Read More
![Dev Prakash Sharma](https://www.tutorialspoint.com/assets/profiles/302800/profile/60_4750-1612521296.jpg)
267 Views
Given an array of 0, 1 and 2 sort the element in an order such that all the zeros come first before 1 and all the 2’s in the end. We have to sort all the elements of the array in-place.We can solve this problem using DNF (Dutch National Flag) Sorting Algorithm. For example, Input-1 −arr[ ]= {2, 0, 0, 1, 2, 1 }Output −0 0 1 1 2 2Explanation − Sorting the given array of elements containing 0, 1 and 2 using the DNF Sorting Algorithm, it will print the output as {0, 0, 1, 1, 2, 2}.Input-2 −arr[ ... Read More
![Dev Prakash Sharma](https://www.tutorialspoint.com/assets/profiles/302800/profile/60_4750-1612521296.jpg)
2K+ Views
Let’s suppose we have given a square matrix of N×N. The task is to rotate the matrix counterclockwise. For example, Input-1 −N = 3 matrix[ ][ ] = [ [1 2 3], [4 5 6], [7 8 9] ]Output −3 6 9 2 5 8 1 4 7Explanation: After rotating the matrix counterclockwise it will generate the output as, 3 6 9 2 5 8 1 4 7.Approach to solve this problemInitially the idea is to find the transpose of the given matrix and then swap each of the elements of the matrix while traversing row-wise.Take Input ... Read More
![Dev Prakash Sharma](https://www.tutorialspoint.com/assets/profiles/302800/profile/60_4750-1612521296.jpg)
869 Views
Let’s suppose we have given an array of integers. The task is to find the index of a particular element in the given array. For example, Input-1 −N = 8 A[ ] = { 1, 2, 4, 3, 3, 1, 1, 5}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus the output is ‘1’.Input-2 −N = 6 A[ ] = {1, 5, 4, 4, 1, 1}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus we can return the output ‘1’.Approach to solve this problemThe given array ... Read More
![Dev Prakash Sharma](https://www.tutorialspoint.com/assets/profiles/302800/profile/60_4750-1612521296.jpg)
459 Views
Let’s suppose we have given an array of unsorted integers. The task is to find the positive missing number which is not present in the given array in the range [0 to n]. For example, Input-1 −N = 9 arr = [0, 2, 5, 9, 1, 7, 4, 3, 6]Output −8Explanation − In the given unsorted array, ‘8’ is the only positive integer that is missing, thus the output is ‘8’.Input-2 −N = 1 arr = [0]Output −1Explanation − In the given array, ‘1’ is the only one positive integer which is missing, thus the output is ‘1’.Approach to solve ... Read More
![Dev Prakash Sharma](https://www.tutorialspoint.com/assets/profiles/302800/profile/60_4750-1612521296.jpg)
821 Views
Suppose we’ve two strings ‘a’ and ‘b’, the task is to find whether we can obtain string ‘b’ by rotating string ‘a’ exactly by 2 places in an anticlockwise or clockwise direction. For example, Input-1 −a = google b = legoogOutput −TrueExplanation − String ‘google’ can be rotated in an anticlockwise direction by two places, which results in the string ‘legoog’. Thus, we return True.Input-2 −a = tuorialst b = tutorialsOutput −FalseExplanation − String ‘tuorialst’ cannot be rotated by two places in any direction to get another string ‘tutorials’. Thus, we return False.The approach used to solve this problemFor the ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
8K+ Views
Given two strings str_1 and str_2. The goal is to count the number of occurrences of substring str2 in string str1 using a recursive process.A recursive function is the one which has its own call inside it’s definition.If str1 is “I know that you know that i know” str2=”know”Count of occurences is − 3Let us understand with examples.For ExampleInputstr1 = "TPisTPareTPamTP", str2 = "TP";OutputCount of occurrences of a substring recursively are: 4ExplanationThe substring TP occurs 4 times in str1.Inputstr1 = "HiHOwAReyouHiHi" str2 = "Hi"OutputCount of occurrences of a substring recursively are: 3ExplanationThe substring Hi occurs 3 times in str1.Approach used ... Read More
![Debomita Bhattacharjee](https://www.tutorialspoint.com/assets/profiles/210947/profile/60_171666-1594382095.jpg)
2K+ Views
We can scroll down with Selenium. Selenium is unable to handle scrolling directly. It takes the help of the Javascript Executor to perform the scrolling action up to an element.First of all we have to locate the element up to which we have to scroll to. Next, we shall use the Javascript Executor to run the Javascript commands. The method executeScript is used to run Javascript commands in Selenium. We shall take the help of the scrollIntoView method in Javascript and pass true as an argument to the method.SyntaxWebElement elm = driver.findElement(By.name("name")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elm);Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ... Read More
![Debomita Bhattacharjee](https://www.tutorialspoint.com/assets/profiles/210947/profile/60_171666-1594382095.jpg)
368 Views
We can simulate a Print screen button with Selenium. The screenshot is captured with the Print screen button. Capturing a screenshot is a three way process. It is an important step towards failure analysis.We shall convert the driver object to TakeScreenshot interface.SyntaxTakesScreenshot s = (TakesScreenshot)driver;Then, with the getScreenshotAs method we shall have an image file and copy that file to a location with FileUtils.copyFile method.SyntaxFile sp=s.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(sp, new File("path of image file"));Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.apache.commons.io.FileUtils; import java.io.File; public class PrintScreenSimulate { public static void main(String[] args) { ... Read More
![Debomita Bhattacharjee](https://www.tutorialspoint.com/assets/profiles/210947/profile/60_171666-1594382095.jpg)
533 Views
We can clear browser cookies in Selenium. The method deleteCookieNamed shall delete a cookie with a specific name. The cookie named is passed as an argument to the method. First, we will add a cookie, then get it and finally delete it.Syntaxdriver.manage().deleteCookieNamed("foo");Another method called the deleteAllCookies deletes all cookies from the existing domain. First, we will add the cookies, then get and delete them.Syntaxdriver.manage().deleteAllCookies();Exampleimport java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class DeleteCookiesViaName{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); ... Read More