Recent Posts

header ads

Java programming - java string programs | KpTechSolution

Some String Concepts, Keywords & Methods Programming :-

java programming-java string-sample java program,java program example| besthindijavatutorials.com
Sample java program-Java String 

 1.Write a java program to Add another String into a declare String.

Source Code :
  1. class StringDemo
    {
    public static void main(String[] arg)
    {
    String str = "IICS";
    str = str+ "-COLLEGE";
    System.out.println(str);
    }
    } 
OUTPUT : IICS-COLLEGE

 2.Write a java program to implement "split" method with loop.

Source Code :
  1. class StringDemo1
    {
    public static void main(String[] arg)
    {
    String str = "THIS IS A PEN";
    String str2[] = str.split("  ");

    for(int i=0;i<str2.length;i++)
    {
    System.out.println(str2[i]);
    }
    }
    }
OUTPUT : THIS IS A PEN

Also Read : java basic programs-java programming.

 3.Write a java program to implement some methods of String concepts.

Source Code :
  1. class StringDemo2
    {
    public static void main(String[] arg)
    {
    String str = "JAVA";
    System.out.println(str.length());
    for(int i=0;i<str.length();i++)

    System.out.println(str.charAt(i));
    System.out.println(str.trim());
    System.out.println(str.replace('A','J'));
    System.out.println(str.concat("  LANGUAGE"));
    }
    }
OUTPUT : 4
                J
                A
                V
                A
               JAVA
               JJVJ
               JAVA  LANGUAGE

Also Read : java basic programs-java programming.

 4.Write a java program to perform 4 String Activities Methods.

Source Code :
  1. class StringDemo3
    {
    public static void main(String[] arg)
    {
    String str = "JAVA language";

    System.out.println(str.indexOf('A'));
    System.out.println(str.lastIndexOf('A'));
    System.out.println(str.toLowerCase());
    System.out.println(str.toUpperCase());
    }
    }
OUTPUT : 1
                3
               java language
               JAVA LANGUAGE

 5.Write a java program to perform 3 another String  Activities Methods using Conditional Statements.

Source Code :
  1. class StringDemo4
    {
    public static void main(String[] arg)
    {
    String str = "IICS-101-JAVA";

    if(str.startsWith("IICS"))
    System.out.println("Valid");
    else
    System.out.println("Invalid");

    if(str.endsWith("JAVA"))
    System.out.println("Valid");
    else
    System.out.println("Invalid");

    int x = "JAVA".compareTo("JAVA");
    if(x==0)
    System.out.println("I am Matches");
    else
    System.out.println("I am Not Matches");
    }
    }
OUTPUT : Valid
                Valid
                I am Matches

Also Read : java basic programs-java programming. 


Like this post, If you find Topic useful in this post, so share it with your friends and colleagues on Facebook, Twitter, whatsapp and Google Plus.

Thank You !

Note - For More Core Java & Advance Java Tutorials, Concepts & Programs Are Available in www.kptechsolution.com  

Post a Comment

0 Comments