Add a Border to the Top and Bottom of an iOS View

Sadiqaadil
Updated on 11-Sep-2019 07:52:04

5K+ Views

In this post we will learn how to add top and bottom border to view.In this example we will take as sample view and add borders to it.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “AddBorderTopAndBottom”Step 2 − Open Main.storyboard add a UIView to it as shown below.Step 3 − Add one @IBOutlet for the view, name it centerView.Step 4 − We will write separate method to add borders to this view. To add borders to this view we will create two layers with desired thickness. We will set the frame of ... Read More

Animate Change of Background Color of a View on iOS

Sadiqaadil
Updated on 11-Sep-2019 07:47:17

2K+ Views

In this post we will learn how to change the background color of view with animation.In this example we will change background color of view on click of a button. On clicking the button the background color will change to red, then on next click it would change to blue, on next click to red again.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “ChangeBGColor”Step 2 − Open Main.storyboard add a button as shown belowStep 3 − Add one @IBAction for touchUpInside of ‘Change Background’ button. Name the function as changeBackgroundClicked.Step 4 − ... Read More

Upcast and Downcast the Same Object in Java

Maruthi Krishna
Updated on 11-Sep-2019 07:22:54

362 Views

Converting one data type to others in Java is known as casting.Up casting − If you convert a higher datatype to lower datatype, it is known as narrowing (assigning higher data type value to the lower data type variable).Example Live Demoimport java.util.Scanner; public class NarrowingExample {    public static void main(String args[]){       char ch = (char) 67;       System.out.println("Character value of the given integer: "+ch);    } }OutputCharacter value of the given integer: CDown casting − If you convert a lower datatype to a higher data type, it is known as widening (assigning lower data type ... Read More

Read Data from PDF File and Display on Console in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:44:22

11K+ Views

There are several libraries to read data from a pdf using Java. Let us see how to read data from a PDF document and display it on the console using a library named PDFBox.You can extract text using the getText() method of the PDFTextStripper class. This class extracts all the text from the given PDF document to use this.Load an existing PDF document using the static method load() of the PDDocument class.Instantiate the PDFTextStripper class.Retrieve.read the contents of the PDF page to a String using the getText() method of the PDFTextStripper class.Finally, close the document using the close() method of ... Read More

Calculate String Buffer Capacity in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:38:26

1K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

Replace Specific Part of String and StringBuffer in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:33:41

332 Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class.Example Live Demopublic class StringExample {    public static void main(String[] args) {       String str = new String("Hello how are you");       System.out.println("Contents of the String: "+str);    } }OutputHello how are youStrings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the ... Read More

Trim White Space in StringBuffer in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:28:48

3K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

Check if Specific String Occurs Multiple Times in Another String in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:24:09

3K+ Views

You can find whether a String contains a specified sequence of characters using any of the methods −The indexOf() method − The indexOf() method of the String class accepts a string value and finds the (starting) index of it in the current String and returns it. This method returns -1 if it doesn’t find the given string in the current one.The contains() method − The contains a () method of the String class accepts a sequence of characters value and verifies whether it exists in the current String. If found it returns true else it returns false.In addition to these, you ... Read More

Split String by Sentence as Delimiter in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:16:45

11K+ Views

The split() method of the String class accepts a String value representing the delimiter and splits into an array of tokens (words), treating the string between the occurrence of two delimiters as one token.For example, if you pass single space “ ” as a delimiter to this method and try to split a String. This method considers the word between two spaces as one token and returns an array of words (between spaces) in the current String.If the String does not contain the specified delimiter this method returns an array containing the whole string as an element.Example Live Demopublic class SplitExample ... Read More

Define Multiple Public Classes in a Java Package

Maruthi Krishna
Updated on 10-Sep-2019 12:45:18

7K+ Views

No, while defining multiple classes in a single Java file you need to make sure that only one class among them is public. If you have more than one public classes a single file a compile-time error will be generated.ExampleIn the following example we have two classes Student and AccessData we are having both of them in the same class and declared both public. Live Demoimport java.util.Scanner; public class Student {    private String name;    private int age;    Student(){       this.name = "Rama";       this.age = 29;    }    Student(String name, int age){   ... Read More

Advertisements