Browsed by
Tag: array

Reversing a string using Stack Implementation

Reversing a string using Stack Implementation

In our previous post, we saw how to create a custom stack implementation in java. Today we are going to extend the same implementation to perform additional operations like reversing, checking empty or full etc. Approach 1: [Simple & Best Approach]   We have used the same Stack class from this post [Java Stack Implementation Simple Example] with small modification like array type changed from int to char.   Modified Stack Class: [Stack.java] package in.javadomain; public class Stack { char item[]; int…

Read More Read More

587 total views, no views today

Property binding angular 4/5/6 example

Property binding angular 4/5/6 example

Property binding angular 4 example: What is property binding ? Binding html properties like disabled[disabled], class[ngClass] and style[ngStyle] dynamically with component values using angular. You can even create your own custom property using @Input. Syntax: [] Eg: [disabled]   Property binding Types: Element property Component property Directive property In our last tutorial we have seen about event binding and twoway binding. As part of that we have created a simple app, 1. Created two text field with technology name and…

Read More Read More

1,582 total views, 7 views today

Array sorting in Java using Comparator Interface

Array sorting in Java using Comparator Interface

Array sorting in Java using Comparator Interface Array can be sorted in ascending and descending order using, Arrays.sort() method. By Implementing Comparator interface. Find the example array sorting programs below. With Comparator Interface Array sorting Example: ArraySorting.java Java File with integer array and Called ArrayReverseOrder and ArrayAscendingOrder using Comparator implemented classes to perform descending and ascending array sorting respectively. package in.javadomain; import java.util.Arrays; public class ArraySorting { public static void main(String[] args) { Integer[] a = { 3, 5, 1,…

Read More Read More

726 total views, no views today

Converting String Array to Integer Array Example Java

Converting String Array to Integer Array Example Java

Java Program to Convert String Array to Integer Array: In this below program we have converted string array to integer array. package in.javadomain; public class StringArrayToIntArray { public static void main(String[] args) { String[] strArray = { "10", "20", "30", "40", "50" }; int[] intArray = new int[strArray.length]; for (int i = 0; i < strArray.length; i++) { intArray[i] = Integer.parseInt(strArray[i]); } for (int i = 0; i < intArray.length; i++) { System.out.println("Integer Array Values :: " + intArray[i]); }…

Read More Read More

856 total views, no views today

JSON in PHP Example

JSON in PHP Example

PHP Program Sample: <?php $place = ‘Arcot’; $pincode = ‘632503’; $place_pincode = array($place=>$pincode); $json_value = json_encode ($place_pincode); echo $json_value; ?> Output: {“Arcot”:”632503″} 743 total views, 1 views today

743 total views, 1 views today

Converting Array to Arraylist in Java Example

Converting Array to Arraylist in Java Example

Array to ArrayList: package in.javadomain; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ArrayTOArrayList { public static void main(String[] args) { String[] languagesArray = { "Tamil", "English", "Hindi", "Telugu" }; List<String> langArrayList = new ArrayList<String>(); Collections.addAll(langArrayList, languagesArray); for (Object value : langArrayList) { System.out.println("Value in ArrayList :::" + value); } } } Output: Value in ArrayList :::Tamil Value in ArrayList :::English Value in ArrayList :::Hindi Value in ArrayList :::Telugu Moving Array values to ArrayList: Collections.addAll(langArrayList, languagesArray); 469 total views, no views…

Read More Read More

469 total views, no views today

ArrayList to Array in Java Example

ArrayList to Array in Java Example

ArrayList to Array: The below program converts ArrayList to Array. Java Program: package in.javadomain; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ArrayListTOArray { public static void main(String[] args) { List<String> mobilesList = new ArrayList<String>(); mobilesList.add("Nokia"); mobilesList.add("Karbonn"); mobilesList.add("Micromax"); mobilesList.add("Samsung"); Object[] listToObj = mobilesList.toArray(); String[] mobilesArray = Arrays.copyOf(listToObj, listToObj.length, String[].class); System.out.println("Value in Array is ::: " + mobilesArray[2]); } } Output: Value in Array is ::: Micromax Converting Object Array to String Array: Object[] listToObj = mobilesList.toArray(); String[] mobilesArray = Arrays.copyOf(listToObj,…

Read More Read More

470 total views, no views today

Array vs Arraylist java

Array vs Arraylist java

Array vs ArrayList java: Array: 1. Size must be defined during initialization itself. 2. Size can not be resized once initialized. int[] myArraySize = new int[10]; //Possible int[] myArray = new int[];  // Not possible 3. Size of the array calculated using length. int[] myArr = new int[9];System.out.println("size of the array : "+myArr.length); //prints 9 4. Both objects and primitives can be stored. int[] myArr = new int[9]; //Possible (primitive data type) Integer[] myArrInteger = new Integer[10]; //Possible (wrapper class…

Read More Read More

648 total views, no views today

Array of ArrayList in Java example

Array of ArrayList in Java example

Array of ArrayList: Array of ArrayList has to be typecasted first. ArrayList array has to be initialized first with ArrayList. Then we have to add the values to the ArrayList. Iterator has to be created separately for each arraylist of array. Program: import java.util.ArrayList; import java.util.Iterator; public class ArrayofArrayList { public static void main(String[] args) { ArrayList[] myArrayArrayList = (ArrayList[])new ArrayList[10]; // 10 is the size of the array not arraylist myArrayArrayList[4] = new ArrayList(); //The array has to be…

Read More Read More

531 total views, 1 views today

Int array vs Integer array in java

Int array vs Integer array in java

Int array vs Integer array in java: Both int array and integer array is same in terms of holding the value/assigning the value. But int[] array can store only primitive data types, where as Integer[] array can store objects also. Also only Integer[] array can store “null”.   Int Array: Int array to store primitive data type (int) values. but now you can store Integer (wrapper class objects) as well because of Autoboxing feature in java (only after java 1.5).  …

Read More Read More

659 total views, no views today