en
Feedback
Java Codes Basic to Advance

Java Codes Basic to Advance

Open in Telegram
2 333
Subscribers
No data24 hours
-37 days
-2030 days
Posts Archive
anyone java coder who love java programming and codes much in java ? Who explores capabilities of java ? Say me @Panditsiddharth

40+ java strings methods šŸ‘† Run directly and understand or go in @java_group_pro copy code and you can also edit then run by /jv command

// 44. join()
public class JoinExample {
    public static void main(String[] args) {
        String[] words = {"Hello", "World", "Java"};
        String joinedString = String.join(", ", words);
        System.out.println("Joined string: " + joinedString);
    }
}

// 43. offsetByCodePoints()
public class OffsetByCodePointsExample {
    public static void main(String[] args) {
        String str = "Hello World";
        int index = str.offsetByCodePoints(0, 6);
        System.out.println("Index after moving by code points: " + index);
    }
}

// 42. regionMatches()
public class RegionMatchesExample {
    public static void main(String[] args) {
        String str1 = "Hello World";
        String str2 = "WORLD";
        boolean matches = str1.regionMatches(true, 6, str2, 0, 5);
        System.out.println("Do regions match ignoring case? " + matches);
    }
}

// 41. replaceFirst()
public class ReplaceFirstExample {
    public static void main(String[] args) {
        String str = "apple orange apple orange";
        String replacedString = str.replaceFirst("apple", "banana");
        System.out.println("String after replacing first occurrence: " + replacedString);
    }
}

// 40. stripLeading(), stripTrailing()
public class StripLeadingTrailingExample {
    public static void main(String[] args) {
        String str = "  Hello, World!  ";
        String strippedLeading = str.stripLeading();
        String strippedTrailing = str.stripTrailing();
        System.out.println("Leading stripped string: '" + strippedLeading + "'");
        System.out.println("Trailing stripped string: '" + strippedTrailing + "'");
    }
}

// 39. repeat(int count)
public class RepeatCountExample {
    public static void main(String[] args) {
        String str = "Java ";
        String repeatedString = str.repeat(3);
        System.out.println("Repeated string: " + repeatedString);
    }
}

// 38. indent(int n)
public class IndentExample {
    public static void main(String[] args) {
        String str = "Hello\nWorld";
        String indentedString = str.indent(4);
        System.out.println("Indented string:\n" + indentedString);
    }
}

// 37. translateEscapes()
public class TranslateEscapesExample {
    public static void main(String[] args) {
        String str = "Hello\\nWorld\\tJava";
        String translatedString = str.translateEscapes();
        System.out.println("Translated escapes: " + translatedString);
    }
}

// 36. stripIndent()
public class StripIndentExample {
    public static void main(String[] args) {
        String str = "    Line 1\n    Line 2\n    Line 3";
        String strippedString = str.stripIndent();
        System.out.println("Stripped indents:\n" + strippedString);
    }
}

// 35. formatted()
public class FormattedExample {
    public static void main(String[] args) {
        String formattedString = "Name: %s, Age: %d";
        String result = String.format(formattedString, "John", 30);
        System.out.println("Formatted string: " + result);
    }
}

// 34. lines().count()
public class LinesCountExample {
    public static void main(String[] args) {
        String str = "Hello\nWorld\nWelcome";
        long lineCount = str.lines().count();
        System.out.println("Number of lines: " + lineCount);
    }
}

// 33. isBlank()
public class IsBlankExample {
    public static void main(String[] args) {
        String str = "   ";
        boolean isBlank = str.isBlank();
        System.out.println("Is the string blank? " + isBlank);
    }
}

// 32. stripTrailing()
public class StripTrailingExample {
    public static void main(String[] args) {
        String str = "  Hello, World!  ";
        String strippedString = str.stripTrailing();
        System.out.println("Trailing stripped string: '" + strippedString + "'");
    }
}

// 31. stripLeading()
public class StripLeadingExample {
    public static void main(String[] args) {
        String str = "  Hello, World!  ";
        String strippedString = str.stripLeading();
        System.out.println("Leading stripped string: '" + strippedString + "'");
    }
}

// 30. lines()
public class LinesExample {
    public static void main(String[] args) {
        String str = "Hello\nWorld\nWelcome";
        String[] lines = str.lines().toArray(String[]::new);
        System.out.println("Individual lines:");
        for (String line : lines) {
            System.out.println(line);
        }
    }
}

// 29. repeat()
public class RepeatExample {
    public static void main(String[] args) {
        String str = "Hello! ";
        String repeatedString = str.repeat(3);
        System.out.println("Repeated string: " + repeatedString);
    }
}

// 28. strip()
public class StripExample {
    public static void main(String[] args) {
        String str = "  Hello, World!  ";
        String strippedString = str.strip();
        System.out.println("Stripped string: '" + strippedString + "'");
    }
}

// 27. intern()
public class InternExample {
    public static void main(String[] args) {
        String str1 = new String("Hello");
        String str2 = str1.intern();
        System.out.println("Interned string: " + str2);
    }
}