Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- public class WorkingWithStrings
- {
- public static void main(String[] args)
- {
- int num = 25;
- //num has direct accesss to val 25
- String s1 = "this is a string";
- //string has direct access to mem adress not string
- //this is normal strign syntax
- //variables we create from a class like strign an int are called 'refrence varaibles'
- System.out.println(s1);
- String s2 = new String ("this is also string");
- //means string s2 = "this os also a string"
- // called class constructor string
- System.out.println("\n"+ s2);
- ////////////////////////////////////////////////////////////////////////////////
- String greeting = "gm ";
- String nameFour = "mitchell";
- String fConcat = greeting + nameFour + "you are in room "+ 332;
- System.out.println(fConcat);
- int stngSize = nameFour.length(); // returns amt of characters in the string
- System.out.println(stngSize);// spaces included
- String nom5 = "mr. pettis class";
- int stringSize = nom5.length();
- System.out.println(stringSize);
- //////////////////////////////////////////////////////////////////////////////////////
- //.toUpperCase()
- String outA = nom5.toUpperCase();
- System.out.println(outA);
- ////////////////////////////////////////////////////////////////////////////
- //.toLowerCase()
- String outB = nom5.toLowerCase();
- System.out.println(outB);
- ///////////////////////////////////////////////////////////////////
- //.charAt()
- char r = nom5.charAt(6);
- System.out.println(r);
- // first letter is 0
- ///////////////////////////////////////////////////////////
- //.indexOf("")
- System.out.println("first occurance of letter \"t\" is "+nom5.indexOf("t"));
- // to put double quotes inside ur argument put backslash before it ex \"t\"
- ///////////////////////////////////////////////////
- //.contains("")
- System.out.println(" the contains method checks if the string contains 'petti': "+ nom5.contains("petti"));
- //returns true or false
- // case sensitivce^^^^^
- //this makes it case INSENSITIVE, aslo shows adding them
- System.out.println(nom5.toUpperCase().contains("PETTI"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement