Delete All Elements from ArrayList for ListView in Android

karthikeya Boyini
Updated on 29-Jun-2020 15:48:40

1K+ Views

This example demonstrate about How to delete all elements from arraylist for listview in AndroidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                                             In the above code, we have taken name as Edit text, when user click on save button it will store the data into arraylist. Click on delete ... Read More

Get Length of an Object in JavaScript

vineeth.mariserla
Updated on 29-Jun-2020 15:08:09

2K+ Views

The length property is only applicable to arrays and strings. So when we call the length property on an object we will get undefined.ExampleLive Demo    var object = {prop:1, prop:2};    document.write(object.length); OutputundefinedWhereas arrays and strings will display their length when length property is used on them.ExampleLive Demo    var string = 'hello';    var array = [1, 2, 3];    var len1 = string.length;    var len2 = array.length;    document.write(len1);    document.write("");    document.write(len2); Output5 3In javascript, we have Object.keys() property, which checks whether there are any properties or not. If we use the length property ... Read More

Main Shift Operators in Java Explained with Example

Narasimha Murthi
Updated on 29-Jun-2020 15:05:55

165 Views

Java provides three shift operators namely −Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.Shift right zero fill operator. The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.Example Live Demopublic class Test {    public static void main(String args[]) {       int a = 60;/* 60 = 0011 1100 */   ... Read More

Importance of Enumerable Attribute in JavaScript Object Properties

vineeth.mariserla
Updated on 29-Jun-2020 15:04:55

349 Views

We can define a property of an object using Dot and Bracket notations. There is also another way in which a property called Object.defineProperty() is used to define a property. It usually takes 3 parameters they are object name, property name, property descriptor.syntaxObject.defineProperty(object name, property name, property descriptor)Lets' define a property with this method.ExampleIn the following example, initially, the object has only one property named 'one'. Later on, another property named 'two' is added. Now when we tried to display all the properties, only the first property was displayed but not the added property as shown in the output.Live Demo   ... Read More

Use of StringBuffer Class in Java with Example

Narasimha Murthi
Updated on 29-Jun-2020 15:02:48

146 Views

The java.lang.StringBuffer class is a thread-safe, mutable sequence of characters. Following are the important points about StringBuffer −A string buffer is like a String, but can be modified.It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.They are safe for use by multiple threads.Every string buffer has a capacity.Example Live Demoimport java.lang.*; public class StringBufferDemo {    public static void main(String[] args) {       StringBuffer buff = new StringBuffer("tutorials ");       System.out.println("buffer = " + buff);       // appends the string argument to ... Read More

Compare Strings in Java: Multiple Methods Explained with Examples

Narasimha Murthi
Updated on 29-Jun-2020 15:01:58

189 Views

We can compare Strings in Java using the compareTo() method and the == operator.comapareTo() method − The compareTo() method compares two strings lexicographically.The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.The == operator − You can compare two strings using == operator. But, it compares references of the given variables not values.The equals() method of the String class accepts a String as parameter and it compares the current string to the specified object. The result ... Read More

Significance of the StringTokenizer Class in Java

Narasimha Murthi
Updated on 29-Jun-2020 15:01:27

242 Views

The java.util.StringTokenizer class allows an application to break a string into tokens.This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.Its methods do not distinguish among identifiers, numbers, and quoted strings.This class methods do not even recognize and skip comments.Example Live Demoimport java.util.*; public class StringTokenizerDemo {    public static void main(String[] args) {       // creating string tokenizer       StringTokenizer st = new StringTokenizer("Tutorialspoint is the best site");       // counting tokens       System.out.println("Total tokens : " + st.countTokens());    } }OutputTotal tokens : 5

Java StringJoiner Class in Java 8

Narasimha Murthi
Updated on 29-Jun-2020 15:00:44

173 Views

This class is used Join a sequence of characters separating using the delimiter.Examplepublic class StringJoinerSample {    public static void main(String[] args){       StringJoiner sj = new StringJoiner(", ");       sj.add("Krishna");       sj.add("Raju");       sj.add("Satish");       sj.add("Pruthvi");       System.out.println(sj);    } }OutputKrishna, Raju, Satish, Pruthvi

Explain Equals Method of Object, String, and StringBuffer Classes

Narasimha Murthi
Updated on 29-Jun-2020 15:00:03

4K+ Views

To compare two objects the object class provides a method with name equals(), this method accepts an object and compares it with the current object. If the references of these two objects are equal, then it returns true else this method returns false.ExampleIn the following example we have a class Employee with two variables name, age and a parameterized constructor.From the main method we are creating two objects by passing same values and, comparing both values using the equals() method.Since the equals() method of the Object class returns true only if the references of the two objects are equal, this ... Read More

Difference Between Object and Reference in Java

Narasimha Murthi
Updated on 29-Jun-2020 14:58:28

11K+ Views

A class in a blue print/user defined datatype in java that describes the behavior/state that the object of its type support.Examplepublic class Student {    String name "Krishna";    int age = 20;    void greet() {       System.out.println("Hello how are you");    } }An object is an instance of a class created from it using the new keyword. Once you create an object of a class, using it you can access he members of the class. In the below given code an object of the class Student is created.public class Example {    public static void main(String ... Read More

Advertisements