Java Code
Java Code
//////////////////////////////////////////////////////////////////////
/////////////////////Multi-Dimensional
Array///////////////////////////////////////////
//////////////////Array List//////////////////////////////////////////////////////
////////////////////////Sorting array
list/////////////////////////////////////////////////////////////
///////////////////////HashMap//////////////////////////////////////////////////
//////////////////////
HashSet////////////////////////////////////////////////////////
//////////////////Access
Modifiers///////////////////////////////////////////////////
A)Access Modifiers
2) For attributes, methods and constructors, you can use the one of the following:
Modifier Description
public The code is accessible for all classes
private The code is only accessible within the declared class
default The code is only accessible in the same package. This is used when you
don't specify a modifier. You will learn more about packages in the Packages
chapter
protected The code is accessible in the same package and subclasses. You will
learn more about subclasses and superclasses in the Inheritance chapter
B) Non-Access Modifiers
final : The class cannot be inherited by other classes (You will learn more
about inheritance in the Inheritance chapter)
abstract : The class cannot be used to create objects (To access an abstract
class, it must be inherited from another class. You will learn more about
inheritance and abstraction in the Inheritance and Abstraction chapters)
2) For attributes and methods, you can use the one of the following:
//////////////////////////////////////////////////////////////////
Java Polymorphism
Polymorphism means "many forms", and it occurs when we have many classes that are
related to each other by inheritance.
//////////////////Count
words//////////////////////////////////////////////////////////////////////////////
//////////////
///////////////////Reverse a
string ////////////////////////////////////////////////////
////////////////////Sum of an
Array/////////////////////////////////////////////////////////
// Loop through the array elements and store the sum in the sum variable
for (i = 0; i < myArray.length; i++) {
sum += myArray[i];
}
///////////////Add 2 numbers/////////////////////////////////////////////////////
int x = 5;
int y = 6;
int sum = x + y;
System.out.println(sum); // Print the sum of x + y
//////////////////Iterator////////////////////////////////
// Make a collection
ArrayList<String> cars = new ArrayList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
/////////////////////////////////////////////
Java Variables
String ,int,float,char,boolean
/////////////////Count ///////////////////////////////////////////
String someString = "elephant";
char someChar = 'e';
int count = 0;
/////////////////////////////////////////////////////////////
class CountNonWhiteSpaceCharacters {
int count = 0;
///////////////////////////////////////////////////////////
How to count the occurrence of a specific character in java?
class CountOccurencesOfCharacter {
int count=0;
for(int i=0; i < inputString .length(); i++) {
class CountOccurencesOfCharacter {
int count=0;
////////////////////////////////////////////////////////////
class OccurenceOfCharInString {
if(countCharMap.containsKey(c)) {
}
}
///////////////////////////////////////////////////////////////////////////////////