Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String / float Question

 
Amardeep Salkar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str = "Amardeep";
String stra = new String("Amardeep);
or
String strb = new String();

Is String is A primitive or wrapper class ?

Similarly

float flt =10.08f;
Float flt = new Float();
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amardeep Salkar:
String str = "Amardeep";
String stra = new String("Amardeep);
or
String strb = new String();

Is String is A primitive or wrapper class ?

Similarly

float flt =10.08f;
Float flt = new Float();


Neither is String a primitive nor a wrapper. It is a general class in java.util package which is used to work on string like char[] in C++(although char[] of C++ and String of Java are way different).

Float is a wrapper class...also Float constructor must be provided a double, float or String value.
 
Amardeep Salkar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i know float is a primitive and double is a wrapper class

because primitive type of double is float. but what about Float

i.e
float ft = 10.64f
Float flt = new Float(ft);
or
Float flt = new Float();

Reply me if I'm wrong...
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i know float is a primitive and double is a wrapper class


You are wrong. Both float and double are primitive.

type of double is float


Again Wrong...double and float are two separate primitive types.

what about Float


Well every primitive type has a corresponding Wrapper class..this is a list of primitive types and their corresponding wrapper classes.

+-----------+---------+
| primitive | wrapper |
+-----------+---------+
| boolean | Boolean |
| byte | Byte |
| short | Short |
| char |Character|
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
+-----------+---------+
[ August 08, 2008: Message edited by: Ankit Garg ]
 
Dariusz Kordonski
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amardeep, check out: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html . You will find some useful basic information on primitives that should help you undertsand the topic better. Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic