Java-String Comparison

String Comparison We use the == operator for comparing the values of two variables or expressions of any data type, such as int, float, double, char and boolean. But we have to use the equals( ) method of the String class for comparing two strings. This method is used to find the contents are same, … Read more…

string concatenation

Java-String Concatenation

String Concatenation Java defines one operator for string object such as “+”, it is used to concatenate two string. For example, in the following program, the value of the variable ‘date’,’month’ and ‘year’ is being converted to a string that represents this value as a decimal digit character. This is prompted by the fact that it … Read more…

string length

Java-Get Length

Get Length The String class defines a number of methods that allow us to accomplish a variety of string manipulation tasks. The number of characters in a string provided by the length( ) method of the String class. Since it is an instantiated method, we have to invoke it from an object of the String … Read more…

string declaration and initialization java

Java-String

String A string is a sequence of characters. In Java, string is the most important data type. A string is enclosed in quotation marks, as in the case of the example “KrugerPark”. But the quotation marks are not themselves part of the string. The string are useful in representing various types of non-numeric data, such … Read more…

Java-Returning Arrays From Method

Returning Arrays From Method A method may also return an array. For example, in the following program, the method returnData( ) returns an array. Program Program Source class Data { int[] returnData() { return new int[]{20,40,60,80}; } } public class Javaapp { public static void main(String[] args) { Data da = new Data(); int[] getData = da.returnData(); for(int … Read more…

Java-Array as Parameters of Method

Array as Parameters of Method By passing the array name, we are, in fact passing the reference of the array to the called function. The array in the called function now refers to the same array stored in the memory. Program Program Source class Setdata{ void setData(int[] v) { v[0] = 10; v[2] = 30; v[4] … Read more…