Imran_Mohammed

String_in_java_2

Apr 18th, 2022 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. public class NewClass1 {
  2.    
  3.     public static void main(String[] args){
  4.        
  5.         String country = "Bangladesh is a country";
  6.        
  7.         //Showing Character of Passing Index :
  8.         char ch = country.charAt(0);
  9.         System.out.println(ch);
  10.        
  11.        
  12.         //Show ASCII Value of Passing Index :
  13.         int value = country.codePointAt(0);
  14.         System.out.println(value);
  15.        
  16.        
  17.         //Show Position of Passing String:
  18.         int pos = country.indexOf("is");
  19.         System.out.println(pos);
  20.        
  21.        
  22.         //Show Last Index of Passing Character:
  23.         int position = country.lastIndexOf("n");
  24.         System.out.println(position);
  25.        
  26.        
  27.         //Removing First & Last Space of String:
  28.         String s3 = country.trim();
  29.         System.out.println(s3);
  30.        
  31.  
  32.  
  33.  
  34.      String country = "Bangladesh is a country";
  35.        
  36.        
  37.         //Replacing Character :
  38.         String s2 = country.replace('i' , 'j');
  39.         System.out.println(s2);
  40.        
  41.        
  42.         //Splitting Where Passing String(space) :
  43.         String[] s3 = country.split(" ");
  44.         for(String x : s3){
  45.           System.out.println(x);
  46.         }
  47.        
  48.        
  49.         //other(int,floatetc) to String :
  50.         int i=100;
  51.         String a = Integer.toString(i);
  52.         System.out.println(a);
  53.        
  54.        
  55.         //String to other :
  56.         int j =Integer.parseInt(a);
  57.         double d = Double.valueOf(a);
  58.         System.out.println(j);
  59.         System.out.println(d);
  60.        
  61.  
  62.      
  63.     }          
  64. }
  65.  
Add Comment
Please, Sign In to add comment