Advertisement
zachdyer

Java: More String Methods

May 26th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. class Java{
  2.     public static void main(String args[]){
  3.         String business = "Zach Dyer Design";
  4.         //Returns the index of the first "D"
  5.         System.out.println(business.indexOf("D"));
  6.         //Starts to search the string from index 7 and returns 10
  7.         System.out.println(business.indexOf("D",7));
  8.        
  9.         String first = "Zach ";
  10.         String last = "Dyer";
  11.        
  12.         //Concatenate strings
  13.         System.out.println(first + last);
  14.        
  15.         //Concatenate strings
  16.         System.out.println(first.concat(last));
  17.        
  18.         //Replace Zach with Kris and concatenate first and last name
  19.         System.out.println(first.replace("Zach", "Kris") + last);
  20.        
  21.         String boom = "boom";
  22.         //Print string to uppercase
  23.         System.out.println(boom.toUpperCase());
  24.        
  25.         String loud = "I AM SPEAKING LOUD";
  26.         //Prints string to lowercase
  27.         System.out.println(loud.toLowerCase());
  28.        
  29.         String trimString = "    I need some trimming up     ";
  30.         //Cleans up the blank spaces before and after the string.
  31.         System.out.println("<" + trimString.trim() + ">");
  32.        
  33.         //Here some weird stuff
  34.         System.out.println(trimString.getBytes());
  35.         //Some more
  36.         System.out.println(trimString.hashCode());
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement