Professional Documents
Culture Documents
System.out.println( helloString );
3.write a java program the String class includes a method for concatenating two strings ?
MyString(String s)
this.str = s;
return str;
5.write a java program It returns the index within this string of the first occurrence of the specified
substring, starting at the specified index.?
public class StudyTonight {
String str="StudyTonight";
System.out.println(str.indexOf('u'));
System.out.println(str.indexOf('t', 3));
String subString="Ton";
System.out.println(str.indexOf(subString));
System.out.println(str.indexOf(subString,7));
6.write a java program function is used to convert primitive data types into Strings?
String s1 = String.valueOf(num);
System.out.println(s1+"IAmAString");
System.out.println(c);
8.write a java program If we don't override the toString() method and directly print the object, then it
would print the object id.?
System.out.println(c);
str.concat("tonight");
System.out.println(str);
strB.append("tonight");
System.out.println(strB);
class Test {
str.append( "tonight" );
System.out.println(str);
System.out.println(str);
str.reverse();
System.out.println(str);
import java.util.Scanner;
String str;
str=sc.nextLine();
System.out.println("after reversing"+reverse);
sc.close();
String str;
str=sc.nextLine();
System.out.println("char at"+i+":"+str.charAt(i));
sc.close();
import java.util.Scanner;
String str;
Scanner sc=new Scanner(System.in);
str=sc.nextLine();
int len=str.length();
sc.close();
String temp=str.substring(6);
System.out.println(temp);
System.out.println(str.substring(i));
System.out.println(str.contains("nation"));
System.out.println(str.contains("ara"));
}
17.write a java program using string join() method?
String str=String.join("--","welcome","java","world");
System.out.println(str);
String str1="programming";
String str2="programming";
String str3="PROGRAMMING";
String str4="Debug";
System.out.println(str.contains(str1.equals(str2));
System.out.println(str.contains(str1.equals(str3));
System.out.println(str.contains(str1.equals(str4));
String str1="";
String str2="Exam";
System.out.println(str.contains(str1.isEmpty());
System.out.println(str.contains(str2.isEmpty());
String str="programming";
System.out.println(str.contains(str.indexOf('a'));
import java.lang.*;
sbf.appendCodePoint(65);
sbr.reverse();
System.out.println(sbr);
sbl.append("ForGeeks");
System.out.println(sbl);
23.write a Java program to demonstrate conversion from String to StringBuffer and StringBuilder.?
public class Test
System.out.println(sbl);