JAVA

TreeMap | Java

Introduction TreeMap is Red-Black tree based NavigableMap implementation. It implements Map interface similar to HashMap class. The main difference between them is that HashMap is an unordered collection while TreeMap is sorted in the ascending order of its keys. TreeMap is unsynchronized collection class which means it is not suitable [...]

2019-02-02T12:45:51+05:30Categories: Programming|Tags: |

Comparator Interface in Java

Comparator interface is used to order the objects of user-defined classes. A comparator object is capable of comparing two objects of two different classes. Comparator interface is used to order the objects of user-defined class. This interface is present java.util package and contains 2 methods int compare(T o1, T o2) [...]

2018-12-14T21:43:19+05:30Categories: Programming|Tags: |

Sorting in Java

Sorting Example Sorting with Array // toSort = new int[] { 5, 1, 89, 255, 7, 88, 200, 123, 66 }; Arrays.sort(toSort);The unsorted array is now fully sorted: [1, 5, 7, 66, 88, 89, 123, 200, 255] Sorting a List List<Integer> toSortList = Integer.asList(toSort); Collections.sort(toSortList); Comparable Comparable is implemented by [...]

2019-04-20T12:14:00+05:30Categories: Programming|Tags: |

Primitive data types in Java

The eight primitive data types in Java are: boolean, whose values are either true or false char, whose values are 16-bit Unicode characters arithmetic types: integral types byte short int long floating-point types float double     Range of numeric data types :-  

2017-10-23T17:09:27+05:30Categories: Programming|Tags: |

Character Class in Java

Character class wraps a value of the primitive type Java Character in an object. An object of type Character contains a single field whose type is char. Example char ch = 'a'; // Char char uniChar = '\u039A'; // Unicode for char char[] charArray = { 'a', 'b', 'c', 'd', [...]

2017-10-22T13:12:40+05:30Categories: Programming|Tags: |

Java StringBuilder class

StringBuilder class is used to create mutable (modifiable) string. It is same as StringBuffer class except that it is non-synchronized. StringBuilder Constructors StringBuilder ( ), creates an empty StringBuilder and reserves room for 16 characters. StringBuilder ( int size ), create an empty string and takes an integer argument to [...]

2018-12-14T23:19:01+05:30Categories: Programming|Tags: |

Important String API in Java

String class (java.lang.String) represents character strings. All string literals in Java programs, such as abc, are implemented as instances of this class. String objects are immutable, their values cannot be changed after they are created. StringBuilder class support mutable strings. Below is the syntax for creating String String str = "abc"; [...]

2020-05-17T12:37:52+05:30Categories: Programming|Tags: |

int to string conversion and vice versa

String to Integer conversion Integer.parseInt(string) // 'string' is string Integer.valueOf(number); Integer to String conversion Integer.toString(number) // number is int String.valueOf(number) String length string.length() Character (char) to integer (int) '1' - '0'   // Output is integer 1 Character (char) to String Character.toString('C') String to long Long.parseLong(string) Long to String Long.toString(number)

2018-01-20T13:58:08+05:30Categories: Programming|Tags: |

Passing and Returning Objects | Java

Java passes everything by value, and not by reference i.e. objects, arrays (which are objects in Java), primitive types (like ints and floats), etc. – these are all passed by value.  When passing arguments to a method, Java will create a copy or copies of the values inside the original [...]

2019-11-16T19:25:40+05:30Categories: Programming|Tags: |
Go to Top