To delete all whitespaces from a string, use the replaceAll() method and replace every whitespace with empty.Let’s say the following is our string.String str = "This is it!";Now, let us replace the whitespaces that will eventually delete them.String res = str.replaceAll("\s+","");Example Live Demopublic class Demo { public static void main(String []args) { String str = "This is it!"; System.out.println("String: "+str); String res = str.replaceAll("\s+",""); System.out.println("String after deleting whitespace: "+res); } }OutputString: This is it! String after deleting whitespace: Thisisit!
INTEL 8085 has a very enriched Instruction Set. Varieties of instructions it can execute. Instructions will have different Byte counts, ranging from 1-Byte to 3-Bytes. Opcode always occupies 1-Byte in the memory. As we know that, with 8 bits for the opcode, 28 = 256 distinct opcodes are possible. In hexadecimal notation, the opcodes can range from 00H to FFH. Each opcode will correspond to an instruction. Thus from the calculation, it is possible to have 256 instructions in the instruction set of 8085. However, only 246 opcodes are implemented in 8085. They can be classified under 66 types, which ... Read More
In 8085 Instruction set, and specially in its arithmetic group of instructions, we have only add and subtract instructions. 8085 does not have instructions to perform multiplication or division numbers. Now let us discuss the instructions to perform addition operations only.To perform addition of two numbers, 8085 imposes the restriction that one of the operands must be kept in the Accumulator. The other operand can be at any one of the following possible locationsClassificationsExamplesThe other operand can be kept in 8-bit immediate data in the instruction.ADI 43HADI FFHThe other 8-bit operand can be kept in a memory location and whose ... Read More
Argument indices allow programmers to reorder the output. Let us see an example.Example Live Demopublic class Demo { public static void main(String[] args) { System.out.printf("Before reordering = %s %s %s %s %s %s", "one", "two", "three", "four", "five", "six" ); System.out.printf("After reordering = %6$s %5$s %4$s %3$s %2$s %1$s", "one", "two", "three", "four", "five", "six" ); System.out.printf("Before reordering = %d %d %d", 100, 200, 300); System.out.printf("After reordering = %2$d %3$d %1$d", 100, 200, 300); } }OutputBefore reordering = one two three four five six After reordering = ... Read More
Here is our character array.char[] ch = { 'T', 'E', 'S', 'T'};To create string object from the above character array is quite easy. Add the array to the string parameter as shown below −String str = new String(ch);Example Live Demopublic class Demo { public static void main(String[] args) { char[] ch = { 'T', 'E', 'S', 'T'}; String str = new String(ch); System.out.println(str); } }OutputTEST
Here is our character array.char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'};Create string object from some part of a string using the following String constructor. Through this we are fetching substring “IN” from the character array.String str = new String(ch, 4, 2);Example Live Demopublic class Demo { public static void main(String[] args) { char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'}; String str = new String(ch, 4, 2); System.out.println(str); } }OutputIN
To get a string from a subset of the character array elements, use the copyValueOf() method. This method returns a String that represents the character sequence in the array specified.Here is our character array.char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'};Now, let us create a string from the subset of the above array elements.String str = String.copyValueOf(ch, 4, 2);Example Live Demopublic class Demo { public static void main(String[] args) { char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'}; String str = String.copyValueOf(ch, 4, 2); System.out.println(str); } }OutputIN
To extract a substring as an array of characters in Java, use the getChars() method.Let’s say the following is our string and character array.String str = "World is not enough!"; char[] chArr = new char[10];Now, use the getChars() method to extract a substring.str.getChars(13, 19, chArr, 0);The above substring is an array of characters which can be displayed as shown in the complete example below −Example Live Demopublic class Demo { public static void main(String[] args) { String str = "World is not enough!"; char[] chArr = new char[10]; str.getChars(13, 19, chArr, ... Read More
To construct on string from another, firstly take a charcter array for the first string.char ch[] = { 'A', 'M', 'I', 'T' }; String str1 = new String(ch);The above forms first string. Now, let us created another string from the first string.String str2 = new String(str1);In this way, we can easily construct one string from another.Example Live Demopublic class Demo { public static void main(String[] args) { char ch[] = { 'A', 'M', 'I', 'T' }; String str1 = new String(ch); String str2 = new String(str1); String str3 ... Read More
To display number with thousands separator, set a comma flag.System.out.printf( "%,d",78567);The above would result.78, 567Let’s check for bigger numbers.System.out.printf( "%,d", 463758);The above would result.463,758Example Live Demopublic class Demo { public static void main( String args[] ) { System.out.printf( "%,d", 95647 ); System.out.printf( "%,d", 687467 ); System.out.printf( "%,.2f", 7546.21 ); System.out.printf( "%,.2f", 463758.787 ); System.out.printf( "%,.2f", 123456.5 ); } }Output95,647 687,467 7,546.21 463,758.79 123,456.50