Master Java Substrings: Build an Email Slicer for Beginners π§
Learn how to easily extract usernames and domains from emails using Java substrings. Perfect for beginners looking to boost their coding skills! #java #javatutorial #javacourse

Bro Code
17.5K views β’ Dec 5, 2024

About this video
#java #javatutorial #javacourse
This is a beginner's introduction to substrings and we'll use it to code an email slicer that extracts a username and domain from an email address.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// .substring() = A method used to extract a portion of a string
// .substring(start, end)
Scanner scanner = new Scanner(System.in);
String email;
String username;
String domain;
System.out.print("Enter your email: ");
email = scanner.nextLine();
if(email.contains("@")){
username = email.substring(0, email.indexOf("@"));
domain = email.substring(email.indexOf("@") + 1);
System.out.println(username);
System.out.println(domain);
}
else{
System.out.println("Emails must contain @");
}
scanner.close();
}
}
This is a beginner's introduction to substrings and we'll use it to code an email slicer that extracts a username and domain from an email address.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// .substring() = A method used to extract a portion of a string
// .substring(start, end)
Scanner scanner = new Scanner(System.in);
String email;
String username;
String domain;
System.out.print("Enter your email: ");
email = scanner.nextLine();
if(email.contains("@")){
username = email.substring(0, email.indexOf("@"));
domain = email.substring(email.indexOf("@") + 1);
System.out.println(username);
System.out.println(domain);
}
else{
System.out.println("Emails must contain @");
}
scanner.close();
}
}
Tags and Topics
Browse our collection to discover more content in these categories.
Video Information
Views
17.5K
Likes
427
Duration
8:05
Published
Dec 5, 2024
User Reviews
4.6
(3)