English
Follow Us Online
Twitter    YouTube(TM)
Append to file
Append String to File
Add to String Array
Add to Object Array
Add Char to String
Access Inner Class
Access Outer Class
Break out of for loop
Convert String to int
Convert int to String
String to Date object
Convert Double to int
Convert double to int
Call a method
Call method in Class
Call a Class
Call Super Class method
Check if a file exists
Check String is Number
Declare a variable
Declare a String
Declare an Array
Declare constants
Define enum
Define a method
Exit program
Exit a for loop
Exit a method
Format date
Format double
Find current directory
Get current date
Get user input
Get Class name
Java How to A B C D E F G H I J K L M N O P Q R S T U V W Y W Z
Java How to add Char to String
Related Links Add Char to String Access Inner Class Access Outer Class Break out of for loop Next Page >>>
Steps:
  1. Concatenate String with char and assign it to String.
/**
 * Example showing how to add Char to String
 * 
 * @author www.f5java.com
 * @return : void
 */	
public void addCharToString(){
	String personName = "Luci"; //1. String initialization
	char endChar = 'e'; // 2. char initialization
	// 3. Concatenate String with char and assign it to String
	personName = personName + endChar;
	System.out.println("Concatenated String is " + personName);		
}
Java How to access Inner Class
  1. Instantiate Outer Class.
  2. Instantiate Inner Class.
  3. Call the inner class method on inner class handle.
public class OuterClass { // Outer Class
	// Method in Outer Class
	public void outerClassMethod() {
		System.out.println("I am in OuterClassMethod");
	}

	public class InnerClass { // Inner Class
		// Method in Inner Class
		public void innerClassMethod() {
			System.out.println("I am in InnerClassMethod");
		}
	}
}
	
/**
 * Example method demonstrating how to access Inner Class methods
 * 
 * @author www.f5java.com
 * @return : void
 */
public void accessInnerClass() {
	// 1. Instantiate Outer Class
	OuterClass outer = new OuterClass();
	// 2. Instantiate Inner Class
	OuterClass.InnerClass inner = outer.new InnerClass();
	// 3. Call the inner class method on inner class handle
	inner.innerClassMethod();

	// Alternatively you can combine Step 1, 2 & 3
	new OuterClass().new InnerClass().innerClassMethod();
}
Java How to access Outer Class from Inner Class
Steps:
  1. Instantiate the Outer Class and call Outer Class method.
  2. Alternatively, call this reference on Outer Class to access outer class method.
public class OuterClass { // Outer Class
	// Method in Outer Class
	public void outerClassMethod() {
		System.out.println("I am in OuterClassMethod");
	}

	public class InnerClass { // Inner Class
		// Method in Inner Class
		public void innerClassMethod() {
			System.out.println("I am in InnerClassMethod");
		}

	   /**
		* Example method demonstrating how to Outer Class
		* method from Inner Class
		* 
		* @author www.f5java.com
		* @return : void
		*/
		public void accessOuterClass() {
			// 1. Instantiate the Outer Class and call Outer Class method
			new OuterClass().outerClassMethod();
			// 2. Alternatively, call this reference on Outer Class to
			// access outer class method
			OuterClass.this.outerClassMethod();
		}
	}
}