driver.get("https://qaplayground.
dev/apps/popup/#");
webelement open=driver.findelement(by.id("login"));
driver.click(open);
webelement submit=driver.findelement(by.id("//*[@id="wrapper"]/button"));
driver.click(submit);
driver.navigate.to("https://qaplayground.dev/apps/popup/#");
driver.gettext(open);
//td[@headers='CIPLA']/following-sibling::td[1]
class Test{
static int count=0;
Test(){
count++;
System.out.println(count);
}
public static void main(String args[]){
Test c1=new Test();
Test c2=new Test();
Test c3=new Test();
}
}
driver.get(windowhandles);
driver.navigate.to(parentURL);
driver.navigate.backto(childURL);
file srcfile=((TakeScreenshot)driver).getScreenshotas(OutPutype.file);
Certainly! Here's a consolidated reference sheet for common Java `String` methods:
---
## Java `String` Methods Reference Sheet
### **1. `length()`**
- **Description:** Returns the length of the string.
- **Example:**
```java
String str = "Hello";
int length = str.length(); // 5
```
### **2. `charAt(int index)`**
- **Description:** Returns the character at the specified index.
- **Example:**
```java
char ch = str.charAt(1); // 'e'
```
### **3. `substring(int beginIndex)`**
- **Description:** Returns a substring from the specified index to the end of the
string.
- **Example:**
```java
String sub = str.substring(1); // "ello"
```
### **4. `substring(int beginIndex, int endIndex)`**
- **Description:** Returns a substring from the specified begin index to end index.
- **Example:**
```java
String sub = str.substring(1, 4); // "ell"
```
### **5. `indexOf(String str)`**
- **Description:** Returns the index of the first occurrence of the specified
substring.
- **Example:**
```java
int index = str.indexOf("l"); // 2
```
### **6. `indexOf(String str, int fromIndex)`**
- **Description:** Returns the index of the first occurrence of the specified
substring, starting the search at the specified index.
- **Example:**
```java
int index = str.indexOf("l", 3); // 3
```
### **7. `lastIndexOf(String str)`**
- **Description:** Returns the index of the last occurrence of the specified
substring.
- **Example:**
```java
int index = str.lastIndexOf("l"); // 3
```
### **8. `lastIndexOf(String str, int fromIndex)`**
- **Description:** Returns the index of the last occurrence of the specified
substring, searching backward starting at the specified index.
- **Example:**
```java
int index = str.lastIndexOf("l", 2); // 2
```
### **9. `contains(CharSequence sequence)`**
- **Description:** Checks if the string contains the specified sequence of
characters.
- **Example:**
```java
boolean contains = str.contains("ell"); // true
```
### **10. `startsWith(String prefix)`**
- **Description:** Checks if the string starts with the specified prefix.
- **Example:**
```java
boolean starts = str.startsWith("Hel"); // true
```
### **11. `endsWith(String suffix)`**
- **Description:** Checks if the string ends with the specified suffix.
- **Example:**
```java
boolean ends = str.endsWith("lo"); // true
```
### **12. `equals(Object anObject)`**
- **Description:** Compares the string to the specified object for equality.
- **Example:**
```java
boolean isEqual = str.equals("Hello"); // true
```
### **13. `equalsIgnoreCase(String anotherString)`**
- **Description:** Compares the string to the specified string, ignoring case
considerations.
- **Example:**
```java
boolean isEqualIgnoreCase = str.equalsIgnoreCase("HELLO"); // true
```
### **14. `compareTo(String anotherString)`**
- **Description:** Compares the string to the specified string lexicographically.
- **Example:**
```java
int comparison = str.compareTo("Hello"); // 0
```
### **15. `compareToIgnoreCase(String str)`**
- **Description:** Compares the string to the specified string lexicographically,
ignoring case.
- **Example:**
```java
int comparisonIgnoreCase = str.compareToIgnoreCase("HELLO"); // 0
```
### **16. `toUpperCase()`**
- **Description:** Converts all characters in the string to uppercase.
- **Example:**
```java
String upperCase = str.toUpperCase(); // "HELLO"
```
### **17. `toLowerCase()`**
- **Description:** Converts all characters in the string to lowercase.
- **Example:**
```java
String lowerCase = str.toLowerCase(); // "hello"
```
### **18. `trim()`**
- **Description:** Removes leading and trailing whitespace.
- **Example:**
```java
String trimmed = " Hello ".trim(); // "Hello"
```
### **19. `replace(char oldChar, char newChar)`**
- **Description:** Replaces all occurrences of the specified character with a new
character.
- **Example:**
```java
String replaced = str.replace('l', 'x'); // "Hexxo"
```
### **20. `replace(CharSequence target, CharSequence replacement)`**
- **Description:** Replaces all occurrences of the specified sequence with a new
sequence.
- **Example:**
```java
String replaced = str.replace("l", "x"); // "Hexxo"
```
### **21. `split(String regex)`**
- **Description:** Splits the string around matches of the given regular
expression.
- **Example:**
```java
String[] parts = "a,b,c".split(","); // ["a", "b", "c"]
```
### **22. `join(CharSequence delimiter, CharSequence... elements)`**
- **Description:** Concatenates the elements of the array into a single string,
separated by the specified delimiter.
- **Example:**
```java
String joined = String.join("-", "2024", "08", "16"); // "2024-08-16"
```
### **23. `valueOf(int i)`**
- **Description:** Returns the string representation of the specified integer.
- **Example:**
```java
String num = String.valueOf(123); // "123"
```
### **24. `format(String format, Object... args)`**
- **Description:** Returns a formatted string using the specified format string and
arguments.
- **Example:**
```java
String formatted = String.format("Hello %s", "World"); // "Hello World"
```
### **25. `concat(String str)`**
- **Description:** Concatenates the specified string to the end of this string.
- **Example:**
```java
String concatenated = str.concat(" World"); // "Hello World"
```
### **26. `toCharArray()`**
- **Description:** Converts the string to a new character array.
- **Example:**
```java
char[] charArray = str.toCharArray(); // ['H', 'e', 'l', 'l', 'o']
```
### **27. `isEmpty()`**
- **Description:** Checks if the string is empty (i.e., has a length of 0).
- **Example:**
```java
boolean isEmpty = "".isEmpty(); // true
```
### **28. `codePointAt(int index)`**
- **Description:** Returns the Unicode code point at the specified index.
- **Example:**
```java
int codePoint = str.codePointAt(0); // 72 ('H')
```
### **29. `codePointBefore(int index)`**
- **Description:** Returns the Unicode code point before the specified index.
- **Example:**
```java
int codePointBefore = str.codePointBefore(1); // 72 ('H')
```
### **30. `codePointCount(int beginIndex, int endIndex)`**
- **Description:** Returns the number of Unicode code points in the specified text
range.
- **Example:**
```java
int codePointCount = str.codePointCount(0, 5); // 5
```
### **31. `offsetByCodePoints(int index, int codePointOffset)`**
- **Description:** Returns the index within the string that is offset by the
specified number of code points.
- **Example:**
```java
int offset = str.offsetByCodePoints(0, 2); // 2
```
---
This reference sheet covers the most commonly used methods in the `String` class in
Java. It provides a brief description and example code for each method, making it a
handy resource for string manipulation tasks.
int[] arr=[23,45,65,75,68,69]
int largest=0;
int second=0;
for(int i=0;i<arr.length;i++){
if (arr[i]>largest){
largest=arr[i];
}
}
for(int i=0;i<arr.length;i++){
if(arr[i]!=largest){
if(arr[i]>second);
second=arr[i];
}
system.out.print("largest is" +largest);
system.out.print("second largest is" +second);
}
Employee
EmpID, EName, ESalary
Department
DeptID, DName, EmpNumber
write a query to find Employee Name whose salary is greater than 5000 and less than
10000 and whose DName='IT'
P}"{
Select Sel=new Select(driver);
sel.SelectbyName("Name (A to Z)");
<select class="product_sort_container" data-test="product-sort-container"><option
value="az">Name (A to Z)</option><option value="za">Name (Z to A)</option><option
value="lohi">Price (low to high)</option><option value="hilo">Price (high to
low)</option></select>
<div class="inventory_item_price" data-test="inventory-item-price">$7.99</div>
Arraylist <int> price=new Arraylist<int>();
price.add
string s="This is Mahesh"
for (String s:words){
if(s.matches(""[A-Z].*));
syste.out.println(s)}
}
public class Myclass
{
private int x = 10;
static int m1() {
int y = x;
return y;
}
public static void main(String[] args) {
System.out.println(m1()); }
1
1 2
1 2 3
1 2 3 4
int n
for (int x=1;x<=n;x++);{
for (int y=1;y<+x;y++);{
system.out.print(y+"");
}
system.out.printin();
public class Myclass {
static int a = 20;
Myclass() {
a++;
}
void m1() {
a++;
System.out.println(a);
}
public static void main(String[] args)
{
Myclass obj = new Myclass();
Myclass obj2 = new Myclass();
Myclass obj3 = new Myclass();
obj3.m1();
}
}
has context menu
ArrayList<String> cars=new ArrayList<>();
cars.add("BMW");
cars.add("Audi");
String car=cars.get(1);
@DataProvider(name="logindata")
returnObject[][]{
{"user1","pwd1"},
{"user2","pwd2"},
{"user3","pwd3"}
}
@Test(dataProvider="")
git pull
git commit
git push;
POST companyabc.com/employee/addemp
String requestBody="{\n + "\companyname\",\n\"\empname\"}"
int num=121;
int rev=0;
while(num!=0){
rev=rev*10+num%10; //11+110
num=num/10;
}
syso(rev):
webdriver wait= new fluentwait
(timeunit,second).pollingevery(timeunit,second).ignoring(exception.class);
Select sel=new select(element);
webelement element=driver.fin
sel.selectby(id);
get.selectedOptions();
select date as Current_date;
Employee
EmpID, EName, ESalary
Department
DeptID, DName, EmpNumber
write a query to find Employee Name whose salary is greater than 5000 and less than
1000 and whose DName='IT'
SELECT E.EName
from Employee E
JOIN Departement D
E.DeptID=D.DeptID
WHERE E.ESalary>5000 AND E.ESalary <1000 AND D.DName='IT'