Reverse a string in Java

Using built in reverse() method of the StringBuilder class: // Java program to ReverseString using StringBuilder import java.lang.*; import java.io.*; import java.util.*; // Class of ReverseString class ReverseString { public static void main(String[] args) { String input = “StringToReverse”; StringBuilder input1 = new StringBuilder(); // append a string into StringBuilder input1 input1.append(input); // reverse StringBuilder

Advertisements

Enums, Pointers, Aliasing, Garbage Collection, JVM in Java

Enums A special DataType that allows for a variable to be one of a set of pre-defined constants. In Java, you use the enum type (short for enumeration), a special datatype introduced in Java 5 to represent such lists of predefined constants. package springframework.guru.enumexample; enum Days{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; } public void simpleEnumExample(){

Stack and Heap memory

Differences between Stack and Heap Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer’s RAM . Variables allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower, but the heap size is only limited by the size

Difference between abstract class and interface

Interface is a collection of abstract methods. Abstract class is a collection of abstract and regular methods. About Abstract Class : Abstract class is a class that contain complete and abstract (incomplete) both type of member/method and it can not be instantiated, Abstract classes are one of the essential behaviors provided by dotnet. Interface contains only definition / signature of

ArrayList in Java

Arraylist class implements List interface. You can say compare Arraylist as dynamic Array. ArrayList is a resizable-array implementation of the List interface. It implements all optional list operations, and permits all elements, including null. Code Example: import java.util.*; public class ArrayListExample { public static void main(String args[]) { ArrayList obj = new ArrayList(); //Add element at the the array

HashMap in Java

HashMap provides the basic implementation of Map interface of Java. HashMap stores the data in (Key, Value) pairs.  To access a value one must know its key. HashMap doesn’t allow duplicate keys but allows duplicate values. HashMap allows null key also but only once and multiple null values. it is a part of Java’s collection since

Recursion

What is Recursion? The Process of Defining a function or calculating a number by the repeated application of an algorithm. Recursion Consist of: Base Case : When we stop repeating our algorithm Recursion Case: Repeating the algorithm Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the

Dictionary Vs Array | Game: Tower of Hanoi

What is Dictionary ? Whats the difference between Dictionary and a Array? An array is just a sorted list of objects. A dictionary stores key-value pairs. Both arrays and dictionaries are containers and can be read sequentally. arrays can be enumerated by means of an index and dictionaries by means of a key. Arrays maintain

What is Object oriented programming ?

Object oriented programming is a term you will hear and read about often. Not only when it comes to C# but other modern programming languages. Terminology can be very important when you are understanding all the concepts and fully grasp all the functionality of a programming language. C# is an object oriented language. What does