// 03_Strings.java - עבודה עם מחרוזות

public class Strings {
    public static void main(String[] args) {
        String text = "Hello World";

        // אורך וגישה לתווים
        System.out.println("האורך: " + text.length());
        System.out.println("התו הראשון: " + text.charAt(0));
        System.out.println("התו האחרון: " + text.charAt(text.length() - 1));

        // גדולות וקטנות
        System.out.println("\ngrossot: " + text.toUpperCase());
        System.out.println("ktanot: " + text.toLowerCase());

        // חיתוך
        System.out.println("\nsubstring(6): " + text.substring(6));
        System.out.println("substring(0, 5): " + text.substring(0, 5));

        // חיפוש
        System.out.println("\nindexOf('o'): " + text.indexOf('o'));
        System.out.println("lastIndexOf('o'): " + text.lastIndexOf('o'));
        System.out.println("contains('World'): " + text.contains("World"));

        // החלפה
        System.out.println("\nreplace: " + text.replace('l', 'L'));
        System.out.println("replace word: " + text.replace("World", "Java"));

        // trim
        String padded = "   hello   ";
        System.out.println("\n'" + padded + "' -> '" + padded.trim() + "'");

        // פיצול
        String csv = "apple,banana,cherry,date";
        String[] fruits = csv.split(",");
        System.out.println("\nלאחר פיצול:");
        for (String fruit : fruits) {
            System.out.println("  " + fruit);
        }

        // השוואה - תמיד equals, אף פעם לא ==
        String a = "hello";
        String b = "hello";
        System.out.println("\n== : " + (a == b));
        System.out.println("equals: " + a.equals(b));
        System.out.println("equalsIgnoreCase: " + a.equalsIgnoreCase("HELLO"));

        // שרשור
        String first = "נפתלי";
        String last = "שווינגר";
        String full = first + " " + last;
        System.out.println("\nשם מלא: " + full);

        // StringBuilder ליעילות בלולאות
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= 5; i++) {
            sb.append("איבר ").append(i).append(", ");
        }
        System.out.println("StringBuilder: " + sb.toString());

        // המרות
        int num = Integer.parseInt("42");
        double dec = Double.parseDouble("3.14");
        String fromInt = String.valueOf(100);
        System.out.println("\nההמרות: " + num + ", " + dec + ", " + fromInt);
    }
}
