0
0
Javaprogramming~15 mins

Common string methods in Java - Practice Problems & Coding Challenges

Choose your learning style8 modes available
trophyChallenge - 5 Problems
🎖️
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate
2:00remaining
Output of substring and length methods
What is the output of the following Java code?
Java
public class Main {
    public static void main(String[] args) {
        String s = "HelloWorld";
        System.out.println(s.substring(2, 7) + " " + s.length());
    }
}
AlloWo 9
BlloWo 10
CloWor 10
DloWor 9
Attempts:
2 left
💻 code output
intermediate
2:00remaining
Result of toUpperCase and trim methods
What will be printed by this Java program?
Java
public class Main {
    public static void main(String[] args) {
        String s = "  java Programming  ";
        System.out.println(s.trim().toUpperCase());
    }
}
AJAVA PROGRAMMING
BGNIMMARGORP AVAJ
Cjava programming
DAVA PROGRAMMING
Attempts:
2 left
💻 code output
advanced
2:00remaining
Output of replace and equals methods
What is the output of this Java code snippet?
Java
public class Main {
    public static void main(String[] args) {
        String s1 = "apple";
        String s2 = s1.replace('p', 'b');
        System.out.println(s2.equals("abble"));
    }
}
Atrue
Bfalse
CCompilation error
DRuntime exception
Attempts:
2 left
💻 code output
advanced
2:00remaining
Output of indexOf and charAt methods
What will this Java program print?
Java
public class Main {
    public static void main(String[] args) {
        String s = "Programming";
        int index = s.indexOf('g');
        char c = s.charAt(index + 1);
        System.out.println(c);
    }
}
Ai
Bm
Cr
Da
Attempts:
2 left
💻 code output
expert
3:00remaining
Final value of string after chained methods
What is the final output of this Java code?
Java
public class Main {
    public static void main(String[] args) {
        String s = "  Java123 Programming456  ";
        s = s.trim().replaceAll("\\d", "").toLowerCase();
        System.out.println(s);
    }
}
Ajavaprogramming
Bjava123 programming456
Cgnimmargorp avaj
Djava programming
Attempts:
2 left