Advertisement
476179

package lessons; public class WorkingWithStrings { public

Oct 7th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. package lessons;
  2.  
  3. public class WorkingWithStrings
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. int num = 25;
  9. //num has direct accesss to val 25
  10.  
  11. String s1 = "this is a string";
  12. //string has direct access to mem adress not string
  13. //this is normal strign syntax
  14.  
  15. //variables we create from a class like strign an int are called 'refrence varaibles'
  16. System.out.println(s1);
  17.  
  18. String s2 = new String ("this is also string");
  19. //means string s2 = "this os also a string"
  20. // called class constructor string
  21. System.out.println("\n"+ s2);
  22.  
  23. ////////////////////////////////////////////////////////////////////////////////
  24.  
  25. String greeting = "gm ";
  26. String nameFour = "mitchell";
  27. String fConcat = greeting + nameFour + "you are in room "+ 332;
  28. System.out.println(fConcat);
  29.  
  30.  
  31. int stngSize = nameFour.length(); // returns amt of characters in the string
  32. System.out.println(stngSize);// spaces included
  33.  
  34. String nom5 = "mr. pettis class";
  35. int stringSize = nom5.length();
  36. System.out.println(stringSize);
  37.  
  38. //////////////////////////////////////////////////////////////////////////////////////
  39. //.toUpperCase()
  40. String outA = nom5.toUpperCase();
  41. System.out.println(outA);
  42.  
  43.  
  44. ////////////////////////////////////////////////////////////////////////////
  45. //.toLowerCase()
  46. String outB = nom5.toLowerCase();
  47. System.out.println(outB);
  48.  
  49. ///////////////////////////////////////////////////////////////////
  50. //.charAt()
  51. char r = nom5.charAt(6);
  52. System.out.println(r);
  53. // first letter is 0
  54. ///////////////////////////////////////////////////////////
  55. //.indexOf("")
  56. System.out.println("first occurance of letter \"t\" is "+nom5.indexOf("t"));
  57. // to put double quotes inside ur argument put backslash before it ex \"t\"
  58.  
  59. ///////////////////////////////////////////////////
  60. //.contains("")
  61. System.out.println(" the contains method checks if the string contains 'petti': "+ nom5.contains("petti"));
  62. //returns true or false
  63. // case sensitivce^^^^^
  64.  
  65. //this makes it case INSENSITIVE, aslo shows adding them
  66. System.out.println(nom5.toUpperCase().contains("PETTI"));
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement