// Strings


class Oct19 {

	public static void main(String[] args) {

		// Ways to create strings

		// Strings are immutable
		String str0 = "cat";

		String str1 = new String("hat");

		char[] data = {'c', 'a', 't'};
		String str3 = new String(data);

		System.out.println(str3);

		byte[] ascii = {99, 97, 116};
		String str5 = new String(ascii); 	// stores "cat"
	
		String str6 = new String(ascii, 1, 2);  // stores "at"

		String str7 = str5 + " in the " + str1; 	// stores "cat in the hat"

		System.out.println(str7);

		// Preferable to use .equals when comparing strings

		String s1 = "hello";

		String s2 = s1;

		System.out.println(s2);

		System.out.println(s1 == s2);

		String s3 = new String("hello");

		System.out.println(s1 == s3);
	
		System.out.println(s1.equals(s3));  // lexicographically equal	
		
		String s4 = "hello";

		System.out.println(s1 == s4); 

		System.out.println(s1.equals(s4));
		
		// String length

		int arrLen = data.length;
		System.out.println(arrLen);

		int str4Len = s4.length();
		System.out.println(str4Len);	

		// Concatenation

		int x = 10 + 5;  	// 15

		String s5 = "aga: ";
	
		String s6 = s5 + 2;
		System.out.println(s6);		// age: 2
		
		String s7 = s5 + (2 + 30);
		System.out.println(s7);		// age: 32

		// Substrings

		String s8 = str7.substring(11);
		System.out.println(s8);

		String s9 = s8.replace('h', 'P');
		System.out.println(s9);
		System.out.println(s8);

		// Trimming whitespace

		String s10 = " this has white space	";
		String s11 = s10.trim();
		System.out.println("[" + s11 + "]");
 
		
		// Character extraction

		char firstChar = s11.charAt(0);

		char[] buffer = new char[10];
		s11.getChars(5, 8, buffer, 0);

		System.out.println(buffer);
		
	}



}
