std::vector Resize vs std::vector Reserve in C++

Samual Sam
Updated on 30-Jul-2019 22:30:25

3K+ Views

Vectors have the ability to resize itself automatically like dynamic arrays when an element is inserted or deleted, the container handle their storage automatically.The main difference between vector resize() and vector reserve() is that resize() is used to change the size of vector where reserve() doesn’t. reserve() is only used to store at least the number of the specified elements without having to reallocate memory. But in resize() if the number is smaller than the current number then it resizes the memory and deletes the excess space over it.vector::resize()Vector resize() is used to change its size.ExampleSteps in the source code:Begin ... Read More

Restrict UITextField to Take Only Numbers in Swift

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

6K+ Views

In iOS apps sometimes we need to restrict our text field to take only numbers as an input, this can be done in several ways, let’s see some of them.Method 1: Changing the Text Field Type from storyboard.Select the text field that you want to restrict to numeric input.Go to its attribute inspector.Select the keyboard type and choose number pad from there.Method 2: Programmatically limiting inputs to number.Select the text fieldCreate its outlet in the view controller.Conform the view controller to UITextFieldDelegateSet the text field’s delegateAdd the following functionfunc textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool ... Read More

Loop Through Collections with a Cursor in MongoDB

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

Following is the syntax to loop through collections with cursorvar anyVariableName1; var anyVariableName2= db.yourCollectionName.find(); while(yourVariableName2.hasNext()) {    yourVariableName1= yourVariableName2.next(); printjson(yourVariableName1); };Let us create a collection with documents. Following is the query> db.loopThroughCollectionDemo.insertOne({"StudentName":"John", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ca81f2d6669774125247f") } > db.loopThroughCollectionDemo.insertOne({"StudentName":"Larry", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ca8272d66697741252480") } > db.loopThroughCollectionDemo.insertOne({"StudentName":"Chris", "StudentAge":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ca8462d66697741252481") } > db.loopThroughCollectionDemo.insertOne({"StudentName":"Robert", "StudentAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ca8632d66697741252482") }Following is the query to display all documents from a collection with the help of find() method> db.loopThroughCollectionDemo.find().pretty();This will ... Read More

Rename Function in C/C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

407 Views

The C library function int rename(const char *old_filename, const char *new_filename) causes the filename referred to by old_filename to be changed to new_filenameFollowing is the declaration for rename() function.int rename(const char *old_filename, const char *new_filename)The parameters are old_filename − This is the C string containing the name of the file to be renamed and/or moved, new_filename − This is the C string containing the new name for the file.On success, zero is returned. On error, -1 is returned, and errno is set appropriately.Example#include int main () {    int ret;    char oldname[] = "file.txt";    char newname[] = ... Read More

Generation of Time Delay in 8085

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

30K+ Views

In this section we will see how to generate the time delay using 8085 programs. The delay will be used in different places to simulate clocks, or counters or some other area.When the delay subroutine is executed, the microprocessor does not execute other tasks. For the delay we are using the instruction execution times. executing some instructions in a loop, the delay is generated. There are some methods of generating delays. These methods are as follows.Using NOP instructionsUsing 8-bit register as counterUsing 16-bit register pair as counter.Using NOT instructions:One of the main usage of NOP instruction is in delay generation. ... Read More

Addressing Modes in 8086 Microprocessor

Chandu yadav
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see the addressing modes of Intel 8086 microprocessor.There are eight addressing modes in 8086 MPU. These modes are:Immediate Addressing ModeRegister Addressing ModeDirect Addressing ModeRegister Indirect Addressing ModeBased Addressing ModeIndexed Addressing ModeBased-Index Addressing ModeBased-Index with displacement addressing modeImmediate AddressingThe addressing mode in which the data operand is a part of the instruction itself is known as immediate addressing mode.MOV CX, 4929 H, ADD AX, 2387 H, MOV AL, FFH  Register AddressingIt means that the register is the source of an operand for an instruction.MOV CX, AX; copies the contents of the 16-bit AX register into; the ... Read More

Fetch Value in a Java Pair Class Tuple

Samual Sam
Updated on 30-Jul-2019 22:30:25

497 Views

Use the getValueX() method to fetch the value from Pair Tuple class in Java at a particular index. For example, getValue0().Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Pair; public class Demo { ... Read More

Use JSP Forward Action in JSP

Chandu yadav
Updated on 30-Jul-2019 22:30:25

1K+ Views

The forward action terminates the action of the current page and forwards the request to another resource such as a static page, another JSP page, or a Java Servlet.Following is the syntax of the forward action −Following table lists out the required attributes associated with the forward action −Sr.No.Attribute & Description1pageShould consist of a relative URL of another resource such as a static page, another JSP page, or a Java Servlet.ExampleLet us reuse the following two files (a) date.jsp and (b) main.jsp as follows −Following is the content of the date.jsp file −Today's date: Following is the content of the ... Read More

Use Multiple Resource Bundle in Same JSP

Samual Sam
Updated on 30-Jul-2019 22:30:25

369 Views

The tag is used to load a resource bundle and stores it in the named scoped variable or the bundle configuration variable.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultbasenameBase name of the resource bundle family to expose as a scoped or a configuration variableYesNonevarName of the variable to store the new bundleNoReplace defaultscopeScope of the variable to store the new bundleNoPageExample           JSTL fmt:setBundle Tag                     The above code will generate the following result −One Two Three

Find Middle Element in an Array in Android

Anvi Jain
Updated on 30-Jul-2019 22:30:25

153 Views

This example demonstrate about How to find middle element in a array in android.Step 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 a text view to find the middle element.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; import java.lang.reflect.Array; import java.util.LinkedList; public class MainActivity extends AppCompatActivity {    @RequiresApi(api = ... Read More

Advertisements